yusuke0426 yusuke0426 - 4 months ago 12
Python Question

Python: I have pandas dataframe which has the same column name. How to change one of those?

I have pandas dataframe which has the same column names. (column names are a,b,a,a,a)
Below is example.

enter image description here

Is there any way I can change column name only for 3rd column from the left by specifying column location? I found that there is a way to change column name by making a new list. But I wanted to see if there is any way I can specify column location and change the name.
Below is what I want.
enter image description here

Since I am new to programming, I would appreciate any of your help!

Answer

Does this work?:

column_names = df.columns.values
column_names[2] = 'Changed'
df.columns = column_names