Open In App

How to Drop Index Column in Pandas?

Last Updated : 03 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

When working with Pandas DataFrames, it’s common to reset or remove custom indexing, especially after filtering or modifying rows. Dropping the index is useful when:

  • We no longer need a custom index.
  • We want to restore default integer indexing (0, 1, 2, …).
  • We’re preparing data for exports or transformations where index values are not needed.

In this article, we’ll learn how to drop the index column in a Pandas DataFrame using the reset_index() method

Syntax of reset_index()

DataFrame.reset_index(drop=True, inplace=True)

Parameters:

  • drop (bool): If True, the index is reset and the old index is not added as a new column.
  • inplace (bool): If True, modifies the DataFrame in place. If False, returns a new DataFrame.

Return Type:

  • Returns None if inplace=True.
  • Returns a new DataFrame with reset index if inplace=False.

Example: Dropping Index Column from a Dataframe

To demonstrate the function we need to first create a DataFrame with custom indexes and then, use reset_index() method with the drop=True option to drop the index column.

Python
import pandas as pd

data = pd.DataFrame({
    "id": [7058, 7059, 7072, 7054],
    "name": ['Sravan', 'Jyothika', 'Harsha', 'Ramya'],
    "subjects": ['Java', 'Python', 'HTML/PHP', 'PHP/JS']
})

# Set a custom index
data.index = ['student-1', 'student-2', 'student-3', 'student-4']

print('DataFrame with Custom Index:')
print(data)

data.reset_index(drop=True, inplace=True)

print('\nDataFrame after Dropping Index:')
print(data)

Output:

Dropping-the-Index-Column-in-Pandas

DataFrame with Custom Index Column

Explanation:

  • custom index (student-1, student-2, etc.) is assigned to the DataFrame.
  • reset_index(drop=True, inplace=True) resets the index to the default 0-based integers.
  • drop=True prevents the old index from being added as a separate column.
  • inplace=True ensures the original DataFrame is modified directly.

When to Use reset_index

  • Removing Unnecessary Indexes: After filtering or manipulating rows, you may end up with non-sequential or unwanted indexes.
  • Default Indexing: Use it when you want to convert the DataFrame back to its default integer index, especially after setting custom indexes.

Dropping the index column is a simple and efficient way to reset your DataFrame’s index. This method is commonly used when cleaning or reshaping data before analysis.

Related articles:



Next Article

Similar Reads