Using groupby

So far, we have learned how to aggregate over specific windows and over the entire dataframe; however, the real power comes with the ability to aggregate by group membership. This lets us calculate things such as the total precipitation per month per station and average OHLC stock prices for each volume bin we've created.

OHLC is a common abbreviation with stock pricing data; it stands for the prices at open, high, low, and close during a given trading day.

In order to calculate the aggregations per group, we must first call the groupby() method on the dataframe and provide the column(s) we want to be used to determine distinct groups. Let's look at the average of our stock data points for each of the volume traded bins we created ...

Get Hands-On Data Analysis with 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.