I have a dataframe which looks something like this: I am trying to compute a value based on a condition for every row which will apply across the column groupings of A, B, C, D, etc. and count how many of those groups passed the condition, for example, some pseudo-code: Expected output: This would mean the example dataframe would end
Tag: pandas
Matching Two Pandas DataFrames based on values in columns
I’m trying to match job candidates to mentors based on different several variables that would hopefully create a good match. There are two Pandas DataFrames (one for candidates and one for mentors) that I’m trying to connect based on experience, location, desired job, etc. For example I have a mentor DataFrame that might look something like the below: Along with
Python Read Website Table Data into Dataframe
I came to know this source to import data. I tried but not successful in importing the data https://public.opendatasoft.com/explore/embed/dataset/us-zip-code-latitude-and-longitude/table/ my code: Presently I see no data but a string text. Table on the data: Answer JS is creating the table and rendering of javascript in a request does not work. a workaround can be:
Python Dataframe Sum and Rank the Rows based on the group they belong
My df has USA states-related information. I want to rank the states based on its contribution. My code: Expected Answer: Compute state_capacity by summing state values from all years. Then Rank the States based on the state capacity My approach: I am able to compute the state capacity using groupby. I ran into NaN when mapped it to the df.
Concatenate 3 or more column values into a single value, while maintaining dataframe in python
Data Desired Doing However, the other columns are not being maintained. I am still troubleshooting, any suggestion is appreciated Answer
How to plot a wide dataframe with colors and linestyles based on different columns
Here’s a dataframe of mine: Output: I need to plot val1 and val2 over time, in different colors (say green and red). There are also two classes A and B, and I’d like to plot the two classes in different line types (solid and dashed). So if class is A, then val1 might be solid green in the plot, and
Add new column with specific increasing of a quarter using python
I have a dataframe, df, that has a quarters column where I would like to add an additional increased quarters column adjacent to it (increased by 2) Data Desired Doing However this is not adding 2 consistently to the entire column I am still troubleshooting, any suggestion is appreciated Answer Reformat the strings in date in such a way that
Grouping and concatening values in Pandas dataframes
I found an answer to my question in another request on this site, however the answer provided doesn’t work for me so I’m asking in a different request. I will use the same data and show results I’m getting. So basically, I have a dataframe that one column has repeated values that I want to group in a single row,
Pandas conditional counting by date
I want to count all orders done by each customer at each order date, to find out how many orders were done at the time of each order. Input: Expected output: The following code works but is extremely slow. Taking upwards of 10 hours for 100k+ rows. There is certainly a better way. Answer Try sort_values to get dates in
Pandas – Merge rows of dataframe that have a shared value
I have a dataframe with a list of items in the first row and then all the items that were bought with that item in subsequent columns: I want to merge all the items bought with each item into a single row as below: So, all the items bought with Item 1 form the columns next to it. As you