胖鸭 2012-07-05 14:21
浏览 2159
已采纳

在熊猫中重命名列

I have a DataFrame 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 DataFrame 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.

转载于:https://stackoverflow.com/questions/11346283/renaming-columns-in-pandas

  • 写回答

28条回答 默认 最新

  • bug^君 2012-07-05 14:23
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(27条)

报告相同问题?

悬赏问题

  • ¥15 关于#c语言#的问题:这个六个方程输入程序可以得出角度角速度角加速度
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油