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

  1. A groupby on two columns
  2. unstack: the last level becomes columns
  3. Fill gaps while unstacking
  4. stack: columns go back into rows