Menu Close

How to convert index of a Python Pandas dataframe into a column?

Sometimes, we want to convert index of a Python Pandas dataframe into a column.

In this article, we’ll look at how to convert index of a Python Pandas dataframe into a column.

How to convert index of a Python Pandas dataframe into a column?

To convert index of a Python Pandas dataframe into a column, we assign the index value to the column.

For instance, we write

df['index1'] = df.index

to assign the index values we get with df.index to the 'index1‘ column.

Conclusion

To convert index of a Python Pandas dataframe into a column, we assign the index value to the column.

Posted in Python, Python Answers