PYTHON PANDAS DATAFRAME RESHAPING
Reshape pandas dataframe with melt in Python — tutorial and visualization
Convert wide to long with pd.melt
There are many different ways to reshape a pandas dataframe from wide to long form. But the melt()
method is the most flexible and probably the only one you need to use once you learn it well, just like how you only need to learn one method pivot_table()
to reshape from long to wide (see my other post below).
This tutorial will walk you through reshaping dataframes using pd.melt()
or the melt
method associated with pandas dataframes. In other languages like R, melt is also known as gather. Also, R also has a melt
function that works in the same way.