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
From the course: Data Analysis with Python and Pandas
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Basic aggregations4m 14s
-
(Locked)
The groupby() method4m 32s
-
(Locked)
Challenge: groupby()1m 18s
-
(Locked)
Solution: groupby()2m 11s
-
(Locked)
Grouping by multiple columns4m 41s
-
(Locked)
Challenge: Grouping by multiple columns1m 9s
-
(Locked)
Solution: Grouping by multiple columns3m
-
(Locked)
MultiIndex DataFrames7m 39s
-
(Locked)
Modifying a MultiIndex4m 25s
-
(Locked)
Challenge: MultiIndex DataFrames1m 17s
-
(Locked)
Solution: MultiIndex DataFrames4m 1s
-
(Locked)
The agg() method and named aggregations7m 22s
-
(Locked)
Challenge: The agg() method1m 22s
-
(Locked)
Solution: The agg() method3m 1s
-
(Locked)
Pro tip: Transforming DataFrames6m 50s
-
(Locked)
Challenge: Transforming a DataFrame1m 18s
-
(Locked)
Solution: Transforming a DataFrame4m 27s
-
(Locked)
Pivot tables in pandas6m 40s
-
(Locked)
Multiple aggregation pivot tables2m 54s
-
(Locked)
Pro tip: Pivot table heatmaps4m 35s
-
(Locked)
Melting DataFrames6m 26s
-
(Locked)
Challenge: pivot() and melt()1m 4s
-
(Locked)
Solution: pivot() and melt()5m 39s
-
(Locked)
Key takeaways1m 53s
-
(Locked)
-
-
-
-
-
-