O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Stacking using non-hierarchical indexes

To demonstrate stacking, we will look at several examples using a DataFrame object with non-hierarchical indexes. We will begin our examples using the following DataFrame:

Stacking will move one level of the column's index into a new level of the row's index. As our DataFrame only has one level, this collapses a DataFrame object into a Series object with a hierarchical row index:

To access values, we now need to pass a tuple to the indexer of the Series object, which does the lookup with just the index: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required