Python – pandas group by ALL functionality

group-bypandaspython

I'm using the pandas groupby+agg functionality to generate nice reports

aggs_dict = {'a':['mean', 'std'], 'b': 'size'}
df.groupby('year').agg(aggs_dict)

I would like to use the same aggs_dict on the entire dataframe as a single group, with no division to years, something like:

df.groupall().agg(aggs_dict)

or:

df.agg(aggs_dict)

But couldn't find any elegant way to do it.. Note that in my real code aggs_dict is quite complex so it's rather cumbersome to do:

df.a.mean()
df.a.std()
df.b.size()
....

am I missing something simple and nice?

Best Answer

You could also use a function to directly group on:

 df.groupby(lambda x: True).agg(aggs_dict)