Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 488
yusuke0426 Avatar asked Sep 19 '25 12:09

yusuke0426


1 Answers

Does this work?:

column_names = df.columns.values
column_names[2] = 'Changed'
df.columns = column_names
like image 64
Noam Avatar answered Sep 22 '25 04:09

Noam