From the course: Data Analysis with Python and Pandas

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

The groupby() method

The groupby() method

- [Instructor] All right, so let's look at grouping data frames. A lot of the times we're going to be more interested in group level statistics than we are going to be in column level statistics. So being able to group by certain columns or pieces of information will allow us to do things like transform daily data into monthly, roll up transaction level data by store and a lot more. So let's take a look at our original data frame. Here we have this retail data set. We have an ID, a date, a store number, family, and then a few numeric columns. If I wanted to group by, let's say our family and then calculate the sum, we could do that with the help of the groupby method. But a group data frame essentially is going to be a rolled up data frame where we're calculating some summary statistics by this category. In this case, we're calculating them by the family category. So let's take a look at how to do this. To do this, we can use the groupby method and specify a column to group by. The…

Contents