I am running a loop and adding 7 new columns to an existing DataFrame. After each iteration of the loop, I want to change column names of only the new columns added (i.e. last 7 columns). I have tried doing this using following line of code:
df.columns[len(df.columns)-6:len(df.columns)] = ['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7']
This line of code is not working and I am getting an error -
Index does not support mutable operations
I have looked up on various sites but none of the methods help my case. What can I do to change name of only last 7 columns?