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.
Solution: pivot() and melt()
From the course: Data Analysis with Python and Pandas
Solution: pivot() and melt()
- [Instructor] All right everybody, our solution code is up on the right. Let's go ahead and dive into the notebook. Alright, so we have our transactions table here. We want to build a pivot table. So we know we want to call pivot table on this transactions table, but one thing that we want to do is filter to stores that had a non-zero bonus payable, and then create a heat map. So this could have been a challenging operation if you try to filter after creating your pivot table. But one thing that we can do to get around this is just filter all rows in our base table that have a bonus not equal to zero, or we could even say equal to 100. And that will have the effect of not only filtering out any rows that don't have a bonus, right? These are going to be summed to zero. It won't affect our statistics, it will also filter out stores. So let's go ahead and do transactions.lock. And then you want to specify transactions. Bonus_payable is not equal to zero. So in the case that we had other…
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)
-
-
-
-
-
-