I have a DataFrame which contains the results of multiple aggregation functions applied to multiple columns, for example:
bar = pd.DataFrame([
{'a': 1, 'b': 2, 'grp': 0}, {'a': 3, 'b': 8, 'grp': 0},
{'a': 2, 'b': 2, 'grp': 1}, {'a': 4, 'b': 5, 'grp': 1}
])
bar.groupby('grp').agg([np.mean, np.std])
a b
mean std mean std
grp
0 2 1.414214 5.0 4.242641
1 3 1.414214 3.5 2.121320
I want to combine the aggregation results to lists (or tuples):
grp a b
0 [2, 1.414214] [5.0, 4.242641]
1 [3, 1.414214] [3.5, 2.121320]
What would be the proper way to do this?
Thanks in advance!