How to Convert Index of a Pandas dataframe into a Column

Spread the love

Problem –

You have a pandas dataframe and you want to convert the index of the dataframe into a column.

Solution –

Reading a dataset for illustration.

import pandas as pd

url = ''
df = pd.read_csv(url, index_col='Date')

As you can see that we have an index which contains the Date of the trading. Now suppose you want to convert this Date index to a Date column. To do that, you can use the reset_index method in pandas.


If you permanently change the dataframe then pass inplace=True in the reset_index.


Rating: 1 out of 5.

Leave a Reply