Categories
Python Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *