Part 3. Unstacking and Melting
Step by Step Guide: How to Apply Melt & Unstack
Watch the video to learn about two useful reshaping pipeline steps: Melt and Unstack.
It's important to understand that Melt and Unstack are opposite transforms. Melt converts wide-format data to long-format data, while Unstack converts long-format data to wide-format data.
"Wide to Long" and "Long to Wide" steps are useful to solve this:
01. First Fetch Dataset: this example use the Jane and Joe Doe sales dataset
Unstack
Unstacking is a process that involves converting the unique values of an entity into columns, which can help rearrange the data. Know that only one column can be unstacked at a time.
02. Add an Long to Wide (Unstack) step in the reshaping category
03. Select the entity that you want to unstack and choose the variable that you wish to use. Note that the other variables in the dataset will be discarded.
If you don't want the entity name to be used as a prefix for new column names, simply uncheck the 'New column names' option.
04. Click 'Save and Preview Data' to review the updated dataset
Melt
02. Add an Wide to Long (Melt) step in the reshaping category
03. Choose the name for the values and select columns to convert to rows
04. Remember to click 'Save and Preview Data' to review the updated dataset
Know that if you apply melt to a dataset, and then unstack it, you get the same dataset
Don't forget to watch the next video to continue your learning journey!