Index and MultiIndex
Pandas Basics
2 min read
Published Sep 29 2025, updated Oct 24 2025
Guide Sections
Guide Comments
What is an Index?
- Every Pandas Series or DataFrame has an index.
- It labels rows, allowing you to access, slice, and align data.
- By default, a DataFrame gets a RangeIndex (0, 1, 2, …).
Example:
Output:
0,1,2 is the default index.
Custom Index
- You can set a column as the index using
.set_index():
Output:
Now the index is Name, which can be used for label-based access:
Output:
Index Properties and Methods
Attribute / Method | Description |
| Returns the index object |
| Returns column labels (also an Index object) |
| Resets the index to default RangeIndex, optionally keeping old index as column |
| Sets a column as index |
| Sorts rows by index labels |
| Set or get the name of the index |
| Get array of index values |
| Check if index has unique labels |
MultiIndex (Hierarchical Index)
- MultiIndex allows multiple levels of indexing in rows or columns.
- Useful for grouped, hierarchical, or panel-like data.
- MultiIndex works well with
.groupby(),.pivot_table(), and aggregation.
Creating MultiIndex - from arrays
Output:
Region is level 0, Store is level 1.
Creating MultiIndex - from tuples
Accessing MultiIndex data
Single level:
Output:
Specific row:
Output:
Slicing levels:
Resetting and swapping levels
Sorting MultiIndex














