Chapter 14. Restructuring Data into a Tidy Form
All the datasets used in the preceding chapters have not had much or any work done to change their structure. We immediately began processing the datasets in their original shape. Many datasets in the wild will need a significant amount of restructuring before commencing a more detailed analysis. In some cases, an entire project might only be concerned with formatting the data in such a way that it can be easily processed by someone else.
In this chapter, we will cover the following topics:
- Tidying variable values as column names with
stack
- Tidying variable values as column names with
melt
- Stacking multiple groups of variables simultaneously
- Inverting stacked data
- Unstacking after a
groupby
aggregation - Replicating
pivot_table
with agroupby
aggregation - Renaming axis levels for easy reshaping
- Tidying when multiple variables are stored as column names
- Tidying when multiple variables are stored as column values
- Tidying when two or more values are stored...