How to Convert Index to Column in Pandas Dataframe? Last Updated : 01 Jul, 2020 Comments Improve Suggest changes Like Article Like Report 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. Python3 # importing the pandas library as pd import pandas as pd # Creating the dataframe df df = pd.DataFrame({'Roll Number': ['20CSE29', '20CSE49', '20CSE36', '20CSE44'], 'Name': ['Amelia', 'Sam', 'Dean', 'Jessica'], 'Marks In Percentage': [97, 90, 70, 82], 'Grade': ['A', 'A', 'C', 'B'], 'Subject': ['Physics', 'Physics', 'Physics', 'Physics']}) # Printing the dataframe df Output: 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. Python3 import pandas as pd df = pd.DataFrame({'Roll Number': ['20CSE29', '20CSE49', '20CSE36', '20CSE44'], 'Name': ['Amelia', 'Sam', 'Dean', 'Jessica'], 'Marks In Percentage': [97, 90, 70, 82], 'Grade': ['A', 'A', 'C', 'B'], 'Subject': ['Physics', 'Physics', 'Physics', 'Physics']}) # Printing the dataframe df['index'] = df.index df Output: 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. Python3 import pandas as pd df = pd.DataFrame({'Roll Number': ['20CSE29', '20CSE49', '20CSE36', '20CSE44'], 'Name': ['Amelia', 'Sam', 'Dean', 'Jessica'], 'Marks In Percentage': [97, 90, 70, 82], 'Grade': ['A', 'A', 'C', 'B'], 'Subject': ['Physics', 'Physics', 'Physics', 'Physics']}) # Printing the dataframe df.reset_index(level=0, inplace=True) df Output: Comment More infoAdvertise with us Next Article How to Convert Index to Column in Pandas Dataframe? H haniel Follow Improve Article Tags : Python Python-pandas Python pandas-dataFrame Practice Tags : python Similar Reads How to convert index in a column of the Pandas dataframe? Each row in a dataframe (i.e level=0) has an index value i.e value from 0 to n-1 index location and there are many ways to convert these index values into a column in a pandas dataframe. First, let's create a Pandas dataframe. Here, we will create a Pandas dataframe regarding student's marks in a pa 4 min read How to Convert Dataframe column into an index in Python-Pandas? Pandas provide a convenient way to handle data and its transformation. Let's see how can we convert a data frame column to row name or index in Pandas. Create a dataframe first with dict of lists.  Python3 # importing pandas as pd import pandas as pd # Creating a dict of lists data = {'Name':["Akas 2 min read Convert a Dataframe Column to Integer in Pandas Converting DataFrame columns to the correct data type is important especially when numeric values are mistakenly stored as strings. Let's learn how to efficiently convert a column to an integer in a Pandas DataFrameConvert DataFrame Column to Integer - using astype() Methodastype() method is simple 3 min read How to Convert Pandas DataFrame columns to a Series? It is possible in pandas to convert columns of the pandas Data frame to series. Sometimes there is a need to converting columns of the data frame to another type like series for analyzing the data set. Case 1: Converting the first column of the data frame to Series Python3 # Importing pandas module 2 min read How to Convert String to Integer in Pandas DataFrame? Let's see methods to convert string to an integer in Pandas DataFrame: Method 1: Use of Series.astype() method. Syntax: Series.astype(dtype, copy=True, errors=âraiseâ) Parameters: This method will take following parameters: dtype: Data type to convert the series into. (for example str, float, int).c 3 min read Like