Move from Excel to Python with Pandas Transcripts
Chapter: Aggregating, grouping, and merging
Lecture: Concept: Pivot tables and crosstab

Login or purchase this course to watch this video and the rest of the course contents.
0:00 within Excel. The pivot tables probably the most common way that most people group and aggregate data and pandas has a similar functionality.
0:10 In this example, we have a pivot table that will summarize for each company and each product how much say purchased.
0:18 And we can use a similar Pandas command to do the same thing. So here's the pandas command. And instead of passing the Rose,
0:28 which is the terminology that Excel uses, we use index. And in this case, we tell it to index on the company.
0:35 And then we specify which columns to include across the top of the table. In this case, the product we tell it,
0:42 which aggregation function to perform. In this case, we want to some the extended amount.
0:48 There's another somewhat specialized version of the pivot table called the Cross Tab, and it's a similar functionality. But in this case,
0:57 we can use the cross tab to tell us what percentage of products each company purchases of the total. So in this example,
1:04 we have the company's along the rows and the products in the columns. We also tell it to some that extended amount,
1:12 and then when we told to normalize across the columns. It can tells that in this example, 1.7% of all the total book purchases were made by a bots.
1:22 And this is really handy function because you could also normalize across the columns or the index or normalize across all of the data.
1:31 It's a very quick way to summarize your data.

Talk Python's Mastodon Michael Kennedy's Mastodon