Pivot and Melt in Python

From the Pandas cheat sheet ยท Reshape Data ยท verified Aug 2026

Pivot and Melt

Reshape long data to wide form and back.

python
wide = df.pivot(index="date", columns="metric", values="value")
๐Ÿ“Œ pivot requires unique index-column pairs
๐Ÿ’ก pivot_table aggregates duplicate pairs
๐Ÿ” melt converts wide columns into row values
๐ŸŽฏ Use long form for most grouped analysis
pivotmeltreshape

Continue with Pandas

Save the full cheat sheet or work through every related task.

More Python tasks

Back to the full Pandas cheat sheet