Groupby value counts on the dataframe pandas
I use groupby and size Timing 1,000,000 rows
I use groupby and size Timing 1,000,000 rows
You need nunique: If you need to strip ‘ characters: Or as Jon Clements commented: You can retain the column name like this: The difference is that nunique() returns a Series and agg() returns a DataFrame.
You need nunique: If you need to strip ‘ characters: Or as Jon Clements commented: You can retain the column name like this: The difference is that nunique() returns a Series and agg() returns a DataFrame.
A similar question might have been asked before, but I couldn’t find the exact one fitting to my problem. I want to group by a dataframe based on two columns. For exmaple to make this Into this: Meaning that summation on “quantity” column for same “id” and same “product”.
On groupby object, the agg function can take a list to apply several aggregation methods at once. This should give you the result you need: