9 The GroupBy object

This chapter covers

  • Splitting a DataFrame into groups by using the groupby method
  • Extracting first and last rows from groups in a GroupBy object
  • Performing aggregate operations on GroupBy groups
  • Iterating over DataFrames in a GroupBy object

The pandas library’s GroupBy object is a storage container for grouping DataFrame rows into buckets. It provides a set of methods to aggregate and analyze each independent group in the collection. It allows us to extract rows at specific index positions within each group. It also offers a convenient way to iterate over the groups of rows. There’s lots of power packed into a GroupBy object, so let’s see what it’s capable of doing.

9.1 Creating a GroupBy object from scratch

Get Pandas in Action 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.