statwoman
statwoman

Reputation: 398

Changing index name in pandas dataframe

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

Upvotes: 0

Views: 834

Answers (2)

Rabinzel
Rabinzel

Reputation: 7923

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)

Upvotes: 1

gtomer
gtomer

Reputation: 6574

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) 

Upvotes: 1

Related Questions