I have a data frame df and I use several columns from it to groupby:
df
groupby
df[\'col1\',\'col2\',\'col3\',\'col4\'].groupby([\'col1\',\'co
To get multiple stats, collapse the index, and retain column names:
df = df.groupby(['col1','col2']).agg(['mean', 'count']) df.columns = [ ' '.join(str(i) for i in col) for col in df.columns] df.reset_index(inplace=True) df
Produces: