Skip to content Skip to sidebar Skip to footer

Pandas Create Dataframe With Index Name As Column Name

I have an existing dataframe with column name and data. I want to change index.name for dataframe to be column's name. I am confused about multi - indexing how do I do that? Becaus

Solution 1:

It depends if MultiIndex or not.

For single index need:

df.index.name = 'foo'df = df.rename_axis('foo')

For MultiIndex need:

df.index.names = ('foo', 'bar')
df = df.rename_axis(('foo', 'bar'))

Post a Comment for "Pandas Create Dataframe With Index Name As Column Name"