From the course: Advanced Pandas

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Groupby and aggregations using pandas

Groupby and aggregations using pandas

From the course: Advanced Pandas

Start my 1-month free trial

Groupby and aggregations using pandas

- [Instructor] Arguably the most fundamental transformation you can perform in Pandas is the group by function. Time and time again, this function proves its worth. So let's dive in. We'll start with the Iris data. Now let's apply a group by to Iris. In a group by, you determine the dimensions you want to group by, then specify an aggregation method. As a simple example, let's group by species and apply the maximum aggregation. The result gives us the max for each measurement. And we see we have three total species in our dataset. With group by, we can pass several different types of aggregations to multiple variables. To do this, call .ag after the group by and pass a dictionary with the variables you're interested in along with their associated aggregations. So for the sepal length, we return the mean, min, and max, and we'll count sepal width. Now here's our output. Notice the hierarchical column index that's created…

Contents