Book Image

Learning Pandas

By : Michael Heydt
Book Image

Learning Pandas

By: Michael Heydt

Overview of this book

Table of Contents (19 chapters)
Learning pandas
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Apply


After the grouping is performed, we have the ability to perform either aggregate calculations on each group of data resulting in a single value from each group, or to apply a transformation to each item in a group and return the combined result for each group. We can also filter groups based on results of expressions to exclude the groups from being included in the combined results.

Applying aggregation functions to groups

pandas allows the application of an aggregation function to each group of data. Aggregation is performed using the .aggregate() (or in short, .agg()) method of the GroupBy object. The parameter of .agg() is a reference to a function that is applied to each group. In the case of DataFrame, the function will be applied to each column.

As an example, the following code will calculate the mean of the values across each sensor and axis in the grouping mig_l12:

In [20]:
   # calculate the mean for each sensor/axis
   mig_l12.agg(np.mean)

Out[20]:
                     interval...