Skip to Content
Learn Python by Building Data Science Applications
book

Learn Python by Building Data Science Applications

by Philipp Kats, David Katz
August 2019
Beginner
482 pages
12h 56m
English
Packt Publishing
Content preview from Learn Python by Building Data Science Applications

Aggregating the data to calculate summary statistics 

To aggregate values over some grouping, pandas has the groupby operationone of the library's killer features. This function creates a GroupBy object, which can behave as an iterable of (name, group) tuples, or similar to a dataframe, you can select one or many columns the same way you'd do for a dataframe.

Most importantly, those objects have two special methods:

  • agg, which will perform the given aggregation function (say, calculate averages) for each group, and return them as a dataframe with one row per each group.
  •  transform does all of the same—except that it will return the corresponding group's aggregate values for each row in the original dataframe.

The great part of both of ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python for Data Science

Python for Data Science

Yuli Vasiliev
Introduction to Machine Learning with Python

Introduction to Machine Learning with Python

Andreas C. Müller, Sarah Guido

Publisher Resources

ISBN: 9781789535365Supplemental Content