Aggregation

Compute a summary statistic about each group.

In [6]:
grouped.describe()
Out[6]:
baz qux
count mean std min 25% 50% 75% max count mean std min 25% 50% 75% max
foo
one 3.0 2.0 1.0 1.0 1.5 2.0 2.5 3.0 3.0 5.0 1.0 4.0 4.5 5.0 5.5 6.0
two 3.0 5.0 1.0 4.0 4.5 5.0 5.5 6.0 3.0 2.0 1.0 1.0 1.5 2.0 2.5 3.0
In [7]:
grouped.sum()
Out[7]:
baz qux
foo
one 6 15
two 15 6

Apply multiple functions at once.

In [8]:
grouped['baz'].agg(['count', 'sum', 'mean', 'min', 'max'])
Out[8]:
count sum mean min max
foo
one 3 6 2 1 3
two 3 15 5 4 6

Apply different aggregation to the columns of a dataframe.

In [9]:
grouped.agg({'baz': 'sum', 'qux': 'sum'})
Out[9]:
baz qux
foo
one 6 15
two 15 6