Error while naming unnamed columns in Python dataframe

107 views Asked by At

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.

1

There are 1 answers

2
Sreeram TP On BEST ANSWER

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)