Unpivot

Learn how to unpivot a DataFrame with the the melt() method as part of data reshaping.

Unpivoting with melt()

Now that we know how to convert DataFrames from the long to wide format with pivot() and pivot_table(), let's explore the reverse situation of reshaping data from the wide to long format. A wide format DataFrame can be unpivoted with the melt() method that helps reshape it into a long format, comprising of these three output columns:

  • Index column (serves as the identifier variable and can be multiple columns)

  • Variable column

  • Value column

Get hands-on with 1200+ tech skills courses.