DataFrames have two similar methods, stack and melt, to convert horizontal column names into vertical column values. DataFrames have the ability to invert these two operations directly with the unstack and pivot methods respectively. stack/unstack are simpler methods that allow control over only the column/row indexes, while melt/pivot gives more flexibility to choose which columns are reshaped.
Inverting stacked data
Getting ready
In this recipe, we will stack/melt a dataset and promptly invert the operation with unstack/pivot back to its original form.