重新命名大 pandas 中的列 [英] Renaming columns in pandas

查看:102
本文介绍了重新命名大 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆