pandas 删除没有名称的熊猫列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39399712/
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-09-14 01:58:50  来源:igfitidea点击:

Delete pandas column with no name

pythonpandasdataframe

提问by ghost

I know to delete a column I can use df = df.drop('column_name', 1), but how would I remove a column just by indexing which column it is? As in without inserting the name?

我知道要删除我可以使用的列df = df.drop('column_name', 1),但是如何仅通过索引它是哪一列来删除一列?如不插入名称?

Sorry if this question has been repeated I can't seem to find it

抱歉,如果这个问题已被重复,我似乎无法找到它

回答by ode2k

You can delete column by index i

您可以按索引删除列 i

df.drop(df.columns[i], axis=1)

df.drop(df.columns[i], axis=1)

Adapted from duplicate question:

改编自重复问题:

https://stackoverflow.com/a/20301769/3006366

https://stackoverflow.com/a/20301769/3006366