Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

changing column names in pandas ( Index does not support mutable operations- )

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Index does not support mutable operations

What could I do to get around this?

>Solution :

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

df.columns = [1] + list(df.columns[1:])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading