Steps to Convert Index to Column in Pandas DataFrame

Posted by

When creating DataFrames you may run into situations where you need to convert the index into a true column.

In the example below you’ll notice that while we have a “song_id” it is actually a 2 column DataFrame.

final_count_df.reset_index(inplace=True)
final_count = final_count_df.rename(columns = {'index':'song_id'})

Resetting then renaming the index will provide us with a true column. In the example below, we’re low looking at a true 3-column DataFrame.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s