HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonCritical

Renaming column names in Pandas

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
namespandascolumnrenaming

Problem

I want to change the column labels of a Pandas DataFrame from

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


to

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

Solution

Just assign it to the .columns attribute:

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

>>> df.columns = ['a', 'b']
>>> df
   a   b
0  1  10
1  2  20

Code Snippets

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

>>> df.columns = ['a', 'b']
>>> df
   a   b
0  1  10
1  2  20

Context

Stack Overflow Q#11346283, score: 2574

Revisions (0)

No revisions yet.