This is a quick cheatsheet on creating and indexing with Pandas MultiIndexes.
I’m representing values in the DataFrame using symbols. For a DataFrame like the one to the left, the representation I’ll use is the one on the right.
A in the sample
DataFrame is represented by the blue rectangle that look like in the images. As additional examples,
B in the sample
DataFrame is represented by , the row
one is and
two is .
Four ways to create
pd.MultiIndex.from_frameThe column names become the names of the levels.
Creating a sample DataFrame with MultiIndex
You can create a
MultiIndexes as both the index and the columns.
MultiIndex from a group by
You can create up with a
DataFrame with a
MultiIndex by using a
groupby using multiple columns.
This section describes how to select different columns and rows using the
This section uses the
DataFrame below, which has a MultiIndex as the columns and rows.