0PricingLogin
Data Science Academy · Lesson

pivot_table for Cross-Tabs

Summarizing across two dimensions.

From Long Rows to a Grid

When you want a category-by-category summary, pivot_table turns tidy long rows into a clean two-dimensional grid. 🔄

The Three Key Arguments

Every pivot table needs three roles: which column becomes index, which becomes columns, and which values fill the cells.

df.pivot_table(index='region',
               columns='month',
               values='sales')

All lessons in this course

  1. Wide vs Long, and Tidy Data
  2. pivot_table for Cross-Tabs
  3. melt to Go Long
  4. stack, unstack, and MultiIndex
← Back to Data Science Academy