Home > Net >  Changing index name in pandas dataframe
Changing index name in pandas dataframe

Time:09-07

I have a dataframe that looks like this: enter image description here

How can I change the Unnamed: 0 and the blank header of columns so it would look like this: enter image description here

CodePudding user response:

You want to change both the names of index and columns axis.

You can do it like this:

df.index.name = 'BBID'
df.columns.name = 'VALUE_DATE'

or with a chained method like this:

df = df.rename_axis('VALUE_DATE').rename_axis('BBID', axis=1)

CodePudding user response:

Try this:

df.reset_index(inplace=True)
df.rename(columns={df.columns[0]: 'BBID VALUE_DATE'}, inplace=True)
df.set_index('BBID VALUE_DATE' , inplace = True) 
  • Related