Pandas DataFrame Operations - Pivot Tables and Functions

11. Pivot Table

We have seen how grouping lets us explore relationships within a dataset. A pivot table is a similar operation. You have probably encountered it in spreadsheets or some other programs that operate on tables. If you have ever worked with Excel, Pandas can be used to create Excel style pivot tables.

The pivot table takes simple column-wise data as input, and groups the entries into a two-dimensional table to give a multidimensional summary of the data. Hard to understand? Let’s understand the concept with an example!

Say we want to compare the $$$ earned by the various directors per year. We can create a pivot table using pivot_table; we can set index =‘Director’ (row of the pivot table) and get the yearly revenue information by setting columns = ‘Year’:

Get hands-on with 1200+ tech skills courses.