MultiIndex (Pandas)
A MultiIndex is a hierarchical, multi-level index that lets a single axis carry two or more label levels at once, so you can represent higher-dimensional data inside a flat 2-D DataFrame.
Pandas
A MultiIndex turns each row label into a tuple of values across named levels — for example (region, year). This lets you group, slice, and aggregate along several keys without leaving the familiar Series/DataFrame world. It commonly appears after a groupby on multiple keys or a pivot.
You select from it with tuples in .loc, and you can use .xs() to take a cross-section at one level. The stack and unstack methods move levels between the row index and the columns, which is how you reshape long and wide layouts.
MultiIndexes are powerful but can be confusing; many people call reset_index() to flatten the levels back into ordinary columns once the grouping work is done.
Syntax
pd.MultiIndex.from_tuples(tuples, names=[...])Examples
Python
import pandas as pd
mi = pd.MultiIndex.from_tuples([("a",1),("a",2),("b",1)], names=["L1","L2"])
s = pd.Series([10, 20, 30], index=mi)
print(s)Output:
L1 L2
a 1 10
2 20
b 1 30
dtype: int64