+2 votes
2 views
in Python by (3.3k 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 (33.8k 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 (68.3k 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:-

...