O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Applying aggregation functions to groups

An aggregation function can be applied to each group using the .aggregate() (or in short, .agg()) method of the GroupBy object. The parameter of .agg() is a reference to a function that will be applied to each group. In the case of a DataFrame, this function will be applied to each column of data within the group.

The following example demonstrates calculating the mean of the values for each sensor and axis:

As .agg() will apply the method to every column in each group, pandas also calculates the mean of the interval values (which may not be of much practical interest).

The result of the aggregation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required