VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-convert-index-to-column-in-pandas-dataframe/

⇱ How to Convert Index to Column in Pandas Dataframe? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Convert Index to Column in Pandas Dataframe?

Last Updated : 15 Jul, 2025

Pandas is a powerful tool which is used for data analysis and is built on top of the python library. The Pandas library enables users to create and manipulate dataframes (Tables of data) and time series effectively and efficiently. These dataframes can be used for training and testing machine learning models and Analyzing data. 

Converting Index to Columns

By default, each row of the dataframe has an index value. The rows in the dataframe are assigned index values from 0 to the (number of rows - 1) in a sequentially order with each row having one index value. There are many ways to convert an index to a column in a pandas dataframe. Let's create a dataframe.

Output:

👁 Image

Method 1: The simplest method is to create a new column and pass the indexes of each row into that column by using the Dataframe.index function.

Output:

👁 Image

Method 2: We can also use the Dataframe.reset_index function to convert the index as a column. The inplace parameter reflects the change in the dataframe to stay permanent.

Output:

👁 Image
Comment