Ankita
Ankita

Reputation: 5

Error while naming unnamed columns in Python dataframe

Using this code to name the first column in the dataframe: df1 = df1.rename(columns={'Unnamed:0' : 'time'}, inplace=True) This gives me NoneType object.

I tried removing inplace=True but then it just gives back the dataframe just like the original. No update in column name.

Upvotes: -1

Views: 104

Answers (1)

Sreeram TP
Sreeram TP

Reputation: 11907

You should be doing,

df1 = df1.rename(columns={'Unnamed: 0' : 'time'}, inplace=False)

or

df1.rename(columns={'Unnamed: 0' : 'time'}, inplace=True)

Note the column name is Unnamed: 0 (note the space)

Upvotes: 0

Related Questions