December 2018
Beginner to intermediate
682 pages
18h 1m
English
To help further understand stack/unstack, let's use them to transpose the college DataFrame.
If you take a look at the output from step 2, you'll notice that there are two index levels. By default, the unstack method uses the innermost index level as the new column values. Index levels are numbered beginning from zero from the outside. Pandas defaults the level parameter of the unstack method to -1, which refers to the innermost index. We can instead unstack the outermost column using level=0:
>>> college.stack().unstack(0)
There is actually a very simple way ...