重命名 pandas 中的特定列 [英] Rename specific column(s) in pandas

查看:60
本文介绍了重命名 pandas 中的特定列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为data的数据框.我将如何重命名唯一的一列标题?例如gdplog(gdp)?

I've got a dataframe called data. How would I rename the only one column header? For example gdp to log(gdp)?

data =
    y  gdp  cap
0   1    2    5
1   2    3    9
2   8    7    2
3   3    4    7
4   6    7    7
5   4    8    3
6   8    2    8
7   9    9   10
8   6    6    4
9  10   10    7

推荐答案

data.rename(columns={'gdp':'log(gdp)'}, inplace=True)

rename 表明它接受dict作为columns的参数,因此您只需通过一个条目就传递一个dict.

The rename show that it accepts a dict as a param for columns so you just pass a dict with a single entry.

另请参见相关

这篇关于重命名 pandas 中的特定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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