Pivot Tables
Pivot tables reshape data to create summary tables with rows and columns from your data values.
Basic Pivot Table
Create a summary table:
Loading Pandas Playground...
Aggregation Functions
Specify how to aggregate values:
Loading Pandas Playground...
Multiple Values
Pivot multiple columns:
Loading Pandas Playground...
Adding Totals
Include row and column totals:
Loading Pandas Playground...
Handling Missing Values
Fill or handle NaN in pivots:
Loading Pandas Playground...
Multiple Index Levels
Create hierarchical pivots:
Loading Pandas Playground...
Exercise: Sales Pivot
Loading Exercise...
Exercise: Pivot with Totals
Loading Exercise...
Key Points
pivot_table()creates summary tablesindex=for row labels,columns=for column headersvalues=specifies data to aggregateaggfunc=sets aggregation (default is 'mean')margins=Trueadds row/column totalsfill_value=replaces NaN

