Below is the data in which I am facing the issue: id electronics date 101 Mobile 2022-05-30 101 Laptop 2022-05-30 101 Laptop 2022-05-30 101 Laptop 2022-05-30 101 TV 2022-05-30 102 Mobile 2022-05-31 102 Laptop 2022-05-31 I need to find Cumulative sum of ID(Count) based on Month i.e. if the month end then it sh…
Tag: pandas
Pandas dataframe: select list items in a column, then transform string on the items
One of the columns I’m importing into my dataframe is structured as a list. I need to pick out certain values from said list, transform the value and add it to one of two new columns in the dataframe. Before: Name Listed_Items Tom [“dr_md_coca_cola”, “dr_od_water”, “potatoe…
Aggregating Pandas DF – Losing Data
I’m trying to aggregate a pandas df in a way an excel pivot table would. I have one quantitative variable called “Count”. I would like the same qualitative variables to combine and the “Count” data to sum. However, when I am trying to do this with the below code, I see that I am …
Parsing a Pandas Dataframe
I have a dataframe like this; Looking like this in Jupyter notebook output; I want to parse this table so that table name repeats with each field name and column counts remain the same such as the output dataframe will look like; I tried this code from a stackoverfow solution; But it did not work. In the solu…
return index of matching value over columns in dataframe
my input: I trying get over df all range where matching value is true. My code: What I get:* [2, 3, 4, 5] So its correct, but how to get all index over each column in df? In other word, I dont want input manually name of column to get index matching value, but get ouptut per column. So what
Grouping two variables based on third variable bins in python
My intension is to group two variables pairs falling within a third variable’s bin interval. such as: So that I can fetch a XY pair for a particular bin range of third variable, e.g., bin of 25-50 For the same, I tried to sort the “Z” variable and accordingly “X” and “YR…
Combining dummies and count for pandas dataframe
I have a pandas dataframe like this: as a plain text: {‘id;sub_id;value;total_stuff related to id and sub_id’: [‘aaa;1;cat;10’, ‘aaa;1;cat;10’, ‘aaa;1;dog;10’, ‘aaa;2;cat;7’, ‘aaa;2;dog;7’, ‘aaa;3;cat;5’, ‘bbb;1;panda;20…
Pandas – Repeat row if found in list and count
Need help in repeating rows if found in list. If found value in list increment count If more than one instance found then repeat the row by incrementing count Dataframe: Df looks like: Input list: In need output like: Tried something like this to get first matching index so I can repeat the row but not sure h…
How can I separate one row from a data set but repeat in each line some of the variables?
I have a dataset where each row contains information that needs to be separated and printed in different rows, but I need to keep the name of the company on each newly printed row: example dataset These are the headers: These are 2 rows of data: I need to separate one line into as many as I need. Some compani…
Week number not matching with datetime index strftime week number in pandas
I have the following code which converts index to week number as well as another column is added with week number: As you can see there are instances where week 11 is being shown in the index column using df.index.strftime(‘%U’) when the week number is showing as 12 using df.index.isocalendar().we…