Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Pandas · Module

df.reset_index

Resets a DataFrame's index to the default integer index. By default, the former index is retained as column data, but it can instead be discarded or selectively reset for a MultiIndex.

How it works

Call reset_index to replace the current row index with the default integer index. Unless drop=True, the old index is retained as a column; level can limit removal for a MultiIndex, while inplace=True changes the existing DataFrame and returns None.

Syntax

DataFrame.reset_index(*level=None*, ***, *drop=False*, *inplace=False*, *col_level=0*, *col_fill='',* *allow_duplicates=<no_default>*, *names=None*)

Parameters

NameTypeDescription
levelint, str, tuple, or list, default NoneIndex level(s) to remove; accepts an integer, name, tuple, or list. Defaults to all levels.
dropbool, default FalseIf true, discard the old index instead of adding it as a column.
inplacebool, default FalseIf true, modify this DataFrame and return None; otherwise create a result.
col_levelint or str, default 0Column level into which index labels are inserted when columns are hierarchical.
namesint, str, or 1-dimensional list, default NoneLabel used for the inserted index column(s), or a list of labels for a MultiIndex.

Returns

DataFrame or None: a DataFrame with the new index, or None when inplace=True.

Key points

  • The operation changes row labels to the standard integer index.
  • Use level to target particular index levels instead of resetting every level.
  • Leaving level as None resets the complete index.
  • Set drop=True when the former index should not become a data column.
  • inplace controls whether the original object is changed or a separate result is produced.
  • For hierarchical columns, col_level chooses where inserted index labels are placed.

Common mistakes

  • With drop=True, the old index is discarded rather than added as a column.
  • When renaming multiple index levels with names, provide one name per level.

Example: Move and rename the index

import pandas as pd

df = pd.DataFrame(
    {"city": ["Paris", "Tokyo"], "sales": [10, 20]},
    index=[101, 102],
)
result = df.reset_index(names="customer_id")
print(result)

Creates a new DataFrame with the original index in a renamed column and a default integer index.

When to use it

Flatten indexed data

Convert index labels into ordinary tabular data for export, joins, or downstream transformations.

Partially flatten a MultiIndex

Remove only selected levels while preserving the remaining MultiIndex structure.

Rename index data

Assign a meaningful column name while moving index values into the columns.

Interview questions

QWhat does DataFrame.reset_index() do by default?

It replaces the DataFrame's index with the default integer index. By default, the previous index values become a column; drop=True prevents that insertion.

Follow-up: How would you reset only one level of a MultiIndex? Pass that level's integer position or name through level, leaving other levels intact.

QHow do you reset only selected index levels?

level selects which index level or levels to remove, and None removes all levels. It accepts an integer, string, tuple, or list.

Follow-up: What should level contain for several named levels? Use a list or tuple containing those level names.

QWhat does inplace change?

With inplace=False, the method returns a new DataFrame. With inplace=True, it modifies the existing object and returns None.

Follow-up: When is inplace=False preferable? It preserves the original object and makes the transformed result available for assignment or chaining.

  • DataFrame.set_index
  • DataFrame.reindex
  • Series.reset_index

Source: pandas.DataFrame.reset_index. Checked 2026-10-15.