MultiIndex

noun

say it: “MUL-tee IN-deks” /ˈmʌlti ˈɪndɛks/

Row labels in pandas that have two or more levels, such as a neighborhood and then a pizza size inside it.

What is a MultiIndex in pandas?

A MultiIndex is a set of row labels on two or more levels, such as a neighborhood and a pizza size. pandas makes one when you group by two columns; reset_index() turns the levels back into ordinary columns.

import pandas as pd
orders = pd.DataFrame({"neighborhood": ["Elm Park", "Elm Park", "Riverside"],
                       "size": ["small", "large", "small"], "total": [12.0, 20.0, 14.0]})
print(orders.groupby(["neighborhood", "size"])["total"].sum())
# neighborhood  size
# Elm Park      large    20.0
#               small    12.0
# Riverside     small    14.0

In a sentence

  • “reset_index() turned the MultiIndex back into two plain columns.”
  • “Grouping by neighborhood and size gave a MultiIndex with two levels.”

Level: Freelancer · More Python terms at this level

Updated