python:在pandas数据框中重命名单列标题 [英] python: rename single column header in pandas dataframe
本文介绍了python:在pandas数据框中重命名单列标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为 data
的数据框。如何重命名唯一的一个列标题?例如 gdp
to log(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)
重命名
表明它接受一个dict作为列
的参数,所以你只需传递一个带有单个条目的dict。
The rename
show that it accepts a dict as a param for columns
so you just pass a dict with a single entry.
另请参阅相关的
这篇关于python:在pandas数据框中重命名单列标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文