7 MultiIndex DataFrames

This chapter covers

  • Creating a MultiIndex
  • Selecting rows and columns from a MultiIndex DataFrame
  • Extracting a cross-section from a MultiIndex DataFrame
  • Swapping MultiIndex levels

So far on our pandas journey, we’ve explored the one-dimensional Series and the two-dimensional DataFrame. The number of dimensions is the number of reference points we need to extract a value from a data structure. We need only one label or one index position to locate a value in a Series. We need two reference points to locate a value in a DataFrame: a label/index for the rows and a label/index for the columns. Can we expand beyond two dimensions? Absolutely! Pandas supports data sets with any number of dimensions through the use of a

Get Pandas in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.