Python 熊猫按位置重命名列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43759921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 23:23:37 来源:igfitidea点击:
Pandas rename column by position?
提问by Jun Jang
I was just wondering if I can rename column names by their positions. I know how to rename them by their actual names using:
我只是想知道是否可以按位置重命名列名。我知道如何使用它们的实际名称重命名它们:
df.rename(columns = {})
df.rename(columns = {})
How do I do it if I do not know the column names and know only their positions?
如果我不知道列名而只知道它们的位置,我该怎么做?
回答by Exprator
try this
尝试这个
df.rename(columns={ df.columns[1]: "your value" }, inplace = True)
回答by John Zwinck
You can do this:
你可以这样做:
df.rename(columns={ df.columns[1]: "whatever" })