0 votes
1 view
in Data Science by (12.2k points)

I have a DataFrame using pandas and column labels that I need to edit to replace the original column labels.

I'd like to change the column names in a DataFrame A where the original column names are:

['$a', '$b', '$c', '$d', '$e'] 

to

['a', 'b', 'c', 'd', 'e'].

I have the edited column names stored it in a list, but I don't know how to replace the column names.

1 Answer

0 votes
by (17.8k points)

Just assign it to the .columns attribute:

>>> df = pd.DataFrame({'$a':[1,2], '$b': [10,20]})

>>> df.columns = ['a', 'b']

>>> df

   a   b

0  1  10

1  2  20

...