Explore Courses Blog Tutorials Interview Questions
0 votes
in Data Science by (17.6k 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'] 


['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 (41.4k 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

Related questions

+2 votes
2 answers
asked May 25, 2019 in Python by Shubham (3.9k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories