Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
3 views
in Python by (3.9k points)
edited by

I created a dataframe and column labels in pandas and I need to edit in order to replace the original column labels. I want to change the column names in a dataframe Q, and my original column names are:

['$q', '$w', '$e', '$r', '$t']

to 

 ['q', 'w', 'e', 'r', 't'].

All my column names are there in a list, and I don't have any idea how to replace the column names. Please help?  

2 Answers

0 votes
by (46k points)
edited by

You can use .columns attribute to solve  your problem:

>>> df = pd.DataFrame({'$q':[2,3], '$w': [20,30]})
>>> df.columns = ['q', 'w']
>>> df
   q   w
0  2  20
1  3  30

 Cheers....!! Happy Learning.

0 votes
by (106k points)

You can use the below-mentioned code to find the remaining column in Pandas:-

df.columns = df.columns.str.replace('$','')

You can use the following video tutorials to clear all your doubts:-

Browse Categories

...