0PricingLogin
Data Science Academy · Lesson

melt to Go Long

Unpivoting columns into rows.

The Opposite of Pivot

When columns are really values in disguise, melt unpivots them into rows, turning a wide table into tidy long form. 🫠

What melt Produces

Melt creates two new columns: one holding the old column names, one holding their values. Every cell becomes its own row.

pd.melt(df)

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