EEMI

Guided Notes

Pivot Tables & Reshaping

pivot_table, crosstab, and reshaping between wide and long formats with melt and pivot.

Pivot tables in pandas

Slide 1 / 5

A pivot table summarizes data in a grid — the same idea as Excel's PivotTables:

df.pivot_table(index='region', columns='quarter', values='sales', aggfunc='sum')

• index — the row labels. • columns — the column labels. • values — the numbers to summarize. • aggfunc — how to summarize: 'sum', 'mean', 'count', or a list of several.

It's groupby plus unstack in one call.

← Merging & Joining