重新命名大 pandas 中的列 [英] Renaming columns in pandas
本文介绍了重新命名大 pandas 中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更改数据表 A
中的列名,其中原始列名称为: / p>
['$ a','$ b','$ c','$ d','$ e']
至
['a','b','c','d','e']。
我将编辑的列名称存储在列表中,但我不知道如何替换列名称。
解决方案
只需将其分配给 .columns
属性:
>>> df = pd.DataFrame({'$ a':[1,2],'$ b':[10,20]})
>>> df.columns = ['a','b']
>>> df
a b
0 1 10
1 2 20
I have a data table 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 data table 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.
解决方案
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
这篇关于重新命名大 pandas 中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文