Move from Excel to Python with Pandas Transcripts
Chapter: Aggregating, grouping, and merging
Lecture: Concept: Pivot tables and crosstab
0:00 within Excel. The pivot tables probably the most common way that most people group and
0:05 aggregate data and pandas has a similar functionality.
0:09 In this example, we have a pivot table that will summarize for each company and
0:15 each product how much say purchased.
0:17 And we can use a similar Pandas command to do the same thing.
0:21 So here's the pandas command. And instead of passing the Rose,
0:27 which is the terminology that Excel uses,
0:30 we use index. And in this case,
0:32 we tell it to index on the company.
0:34 And then we specify which columns to include across the top of the table.
0:39 In this case, the product we tell it,
0:41 which aggregation function to perform. In this case,
0:44 we want to some the extended amount.
0:47 There's another somewhat specialized version of the pivot table called the Cross Tab,
0:52 and it's a similar functionality. But in this case,
0:56 we can use the cross tab to tell us what percentage of products each company purchases
1:01 of the total. So in this example,
1:03 we have the company's along the rows and the products in the columns.
1:08 We also tell it to some that extended amount,
1:11 and then when we told to normalize across the columns.
1:13 It can tells that in this example,
1:15 1.7% of all the total book purchases were made by a bots.
1:21 And this is really handy function because you could also normalize across the columns or the
1:26 index or normalize across all of the data.
1:30 It's a very quick way to summarize your data.