Pandasdrill

Level 4: Combining and reshaping Exercise 36 of 45 Pro

Index level into columns with unstack

A pandas exercise from Pandasdrill. Solve it with a Python editor in your browser running real pandas, and it is checked the moment you submit.

The task

`s` holds revenue indexed by region and quarter. Use `unstack` so regions are rows and quarters are columns. Missing combinations stay NaN.

What this exercise teaches

unstack takes the last index level and spreads it across columns. Pairs that never occurred become NaN, which is honest: there was no revenue recorded, not a recorded zero.

A hint if you get stuck

unstack moves the innermost index level, here quarter, into the columns.

This exercise is part of Pro

Pro unlocks all 45 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.

You create a free account first, so Pro is attached to it.

Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.

Start with the free exercises

More exercises in Combining and reshaping