Skip to main content

__ Back to top

__ ` Ctrl ` \+ ` K `

[ ![pandas 2.2.1 documentation - Home](../_static/pandas.svg) ](../index.html)

Site Navigation

  * [ Getting started ](../getting_started/index.html)
  * [ User Guide ](index.html)
  * [ API reference ](../reference/index.html)
  * [ Development ](../development/index.html)
  * [ Release notes ](../whatsnew/index.html)

  * [ __ GitHub  ](https://github.com/pandas-dev/pandas "GitHub")
  * [ __ Twitter  ](https://twitter.com/pandas_dev "Twitter")
  * [ __ Mastodon  ](https://fosstodon.org/@pandas_dev "Mastodon")

Site Navigation

  * [ Getting started ](../getting_started/index.html)
  * [ User Guide ](index.html)
  * [ API reference ](../reference/index.html)
  * [ Development ](../development/index.html)
  * [ Release notes ](../whatsnew/index.html)

  * [ __ GitHub  ](https://github.com/pandas-dev/pandas "GitHub")
  * [ __ Twitter  ](https://twitter.com/pandas_dev "Twitter")
  * [ __ Mastodon  ](https://fosstodon.org/@pandas_dev "Mastodon")

  * [ 10 minutes to pandas ](10min.html)
  * [ Intro to data structures ](dsintro.html)
  * [ Essential basic functionality ](basics.html)
  * [ IO tools (text, CSV, HDF5, â¦) ](io.html)
  * [ PyArrow Functionality ](pyarrow.html)
  * [ Indexing and selecting data ](indexing.html)
  * MultiIndex / advanced indexing 
  * [ Copy-on-Write (CoW) ](copy_on_write.html)
  * [ Merge, join, concatenate and compare ](merging.html)
  * [ Reshaping and pivot tables ](reshaping.html)
  * [ Working with text data ](text.html)
  * [ Working with missing data ](missing_data.html)
  * [ Duplicate Labels ](duplicates.html)
  * [ Categorical data ](categorical.html)
  * [ Nullable integer data type ](integer_na.html)
  * [ Nullable Boolean data type ](boolean.html)
  * [ Chart visualization ](visualization.html)
  * [ Table Visualization ](style.html)
  * [ Group by: split-apply-combine ](groupby.html)
  * [ Windowing operations ](window.html)
  * [ Time series / date functionality ](timeseries.html)
  * [ Time deltas ](timedeltas.html)
  * [ Options and settings ](options.html)
  * [ Enhancing performance ](enhancingperf.html)
  * [ Scaling to large datasets ](scale.html)
  * [ Sparse data structures ](sparse.html)
  * [ Frequently Asked Questions (FAQ) ](gotchas.html)
  * [ Cookbook ](cookbook.html)

  * [ __ ](../index.html)
  * [ User Guide ](index.html)
  * MultiIndex... 

#  MultiIndex / advanced indexing  #

This section covers  indexing with a MultiIndex  and  other advanced indexing
features  .

See the [ Indexing and Selecting Data  ](indexing.html#indexing) for general
indexing documentation.

Warning

Whether a copy or a reference is returned for a setting operation may depend
on the context. This is sometimes called ` chained  assignment  ` and should
be avoided. See [ Returning a View versus Copy  ](indexing.html#indexing-view-
versus-copy) .

See the [ cookbook  ](cookbook.html#cookbook-selection) for some advanced
strategies.

##  Hierarchical indexing (MultiIndex)  #

Hierarchical / Multi-level indexing is very exciting as it opens the door to
some quite sophisticated data analysis and manipulation, especially for
working with higher dimensional data. In essence, it enables you to store and
manipulate data with an arbitrary number of dimensions in lower dimensional
data structures like ` Series  ` (1d) and ` DataFrame  ` (2d).

In this section, we will show what exactly we mean by âhierarchicalâ
indexing and how it integrates with all of the pandas indexing functionality
described above and in prior sections. Later, when discussing [ group by
](groupby.html#groupby) and [ pivoting and reshaping data
](reshaping.html#reshaping) , weâll show non-trivial applications to
illustrate how it aids in structuring data for analysis.

See the [ cookbook  ](cookbook.html#cookbook-multi-index) for some advanced
strategies.

###  Creating a MultiIndex (hierarchical index) object  #

The [ ` MultiIndex  `
](../reference/api/pandas.Multi