Changing index name in pandas dataframe

Question:

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

Asked By: statwoman

||

Answers:

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) 
Answered By: gtomer

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)
Answered By: Rabinzel
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.