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 ...
Get Learning pandas now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.