1grouped_multiple = df.groupby(['Team', 'Pos']).agg({'Age': ['mean', 'min', 'max']})
2grouped_multiple.columns = ['age_mean', 'age_min', 'age_max']
3grouped_multiple = grouped_multiple.reset_index()
4print(grouped_multiple)
5
1df[['col1', 'col2', 'col3', 'col4']].groupby(['col1', 'col2']).agg(['mean', 'count'])
2
1def f(x):
2 d = {}
3 d['a_sum'] = x['a'].sum()
4 d['a_max'] = x['a'].max()
5 d['b_mean'] = x['b'].mean()
6 d['c_d_prodsum'] = (x['c'] * x['d']).sum()
7 return pd.Series(d, index=['a_sum', 'a_max', 'b_mean', 'c_d_prodsum'])
8
9df.groupby('group').apply(f)
10