pythondataframeunnamed-module

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.


Solution

  • 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)