Top "Pandas-groupby" questions

To be used for grouping variables together based on a given condition.

What is the difference between pandas agg and apply function?

I can't figure out the difference between Pandas .aggregate and .apply functions. Take the following as an example: I load …

python pandas pandas-groupby
Pandas groupby multiple columns, list of multiple columns

I have the following data: Invoice NoStockCode Description Quantity CustomerID Country 536365 85123A WHITE HANGING HEART T-LIGHT HOLDER 6 17850 United Kingdom 536365 71053 WHITE …

python pandas pandas-groupby
Combine duplicated columns within a DataFrame

If I have a dataframe that has columns that include the same name, is there a way to combine the …

python pandas dataframe group-by pandas-groupby
When is it appropriate to use df.value_counts() vs df.groupby('...').count()?

I've heard in Pandas there's often multiple ways to do the same thing, but I was wondering – If I'm trying …

python pandas dataframe pandas-groupby
pandas groupby dropping columns

I'm doing a simple group by operation, trying to compare group means. As you can see below, I have selected …

python pandas dataframe pandas-groupby
Aggregation in pandas

How to perform aggregation with pandas? No DataFrame after aggregation! What happened? How to aggregate mainly strings columns (to lists, …

python pandas dataframe pandas-groupby aggregation
Sorting the grouped data as per group size in Pandas

I have two columns in my dataset, col1 and col2. I want group the data as per col1 and then …

python python-3.x pandas pandas-groupby
pandas groupby where you get the max of one column and the min of another column

I have a dataframe as follows: user num1 num2 a 1 1 a 2 2 a 3 3 b 4 4 b 5 5 I want a dataframe which has …

python pandas pandas-groupby
get first and last values in a groupby

I have a dataframe df df = pd.DataFrame(np.arange(20).reshape(10, -1), [['a', 'a', 'a', 'a', 'b', 'b', 'b', 'c', …

python pandas dataframe group-by pandas-groupby