Home > Back-end >  changing column names in pandas ( Index does not support mutable operations- )
changing column names in pandas ( Index does not support mutable operations- )

Time:08-03

I have this current column name:

print(common_nodes_df.columns[0])
('0', '1')

but when I try to change it to:

common_nodes_df.columns[0] = 1

I get this error:

Index does not support mutable operations

What could I do to get around this?

CodePudding user response:

You must replace the whole column names. In your case,

df.columns = [1]   list(df.columns[1:])

CodePudding user response:

df.rename({'1': 1}, axis=1, inplace=True)

CodePudding user response:

  1. use replace OR
  2. while changing the name use inplace = True
  • Related