Error while naming unnamed columns in Python dataframe

Question:

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.

Asked By: Ankita

||

Answers:

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)

Answered By: Sreeram TP
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.