Skip to content
Advertisement

Tag: dataframe

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’, ‘bbb;1;cat;20’, ‘bbb;2;panda;12’]} The desired output I want is this. Note that there are many different “values” possible, so I would need to automate the creation of dummies variables (nb_animals). But these dummies variables must contain the

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 how to do

How to remove a group of specific rows from a dataframe?

I have a dataframe with 7581 rows and 3 columns (id,text,label). And I have a subgroup of this dataframe of 794 rows. What I need to do is to remove that subgroup of 794 rows (same labels) from the big dataframe of 7581. This is how the subgroup looks like: Photo I have tried to do this: But the following

Pandas dataframe – fillna with last of next month

I’ve been staring at this way too long and I think Ive lost my mind, it really shouldn’t be as complicated as I’m making it. I have a df: Date1 Date2 2022-04-01 2022-06-17 2022-04-15 2022-04-15 2022-03-03 NaT 2022-04-22 NaT 2022-05-06 2022-06-06 I want to fill the blanks in ‘Date2’ where it keeps the values from ‘Date2’ if they are present

Faster alternative to groupby, unstack then fillna

I’m currently doing the following operations based on a dataframe (A) made of two columns with multiple thousands of unique values each. The operations performed on this dataframe are: The output is a table (B) with unique values of col1 in rows and unique values of col2 in columns, and each cell is the count of rows, from the original

Advertisement