pandas · Lesson 7.3 · Pro
stack and unstack
Move an index level into the columns and back, which turns a two-key groupby into a grid.
In this lesson
- A groupby on two columns
- unstack: the last level becomes columns
- Fill gaps while unstacking
- stack: columns go back into rows
Go Pro to read this lesson
Pro unlocks every lesson and practice problem in SQL, Python, pandas and NumPy, with answers and step-by-step explanations.