pandas 使用 Dask 数据框删除列

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

Drop column using Dask dataframe

pythonpython-3.xpandasdask

提问by cs0815

This should work:

这应该有效:

raw_data.drop('some_great_column', axis=1).compute()

raw_data.drop('some_great_column', axis=1).compute()

But the column is not dropped. In pandas I use:

但该列不会被删除。在Pandas中,我使用:

raw_data.drop(['some_great_column'], axis=1, inplace=True)

But inplace does not exist in Dask. Any ideas?

但是就地在 Dask 中不存在。有任何想法吗?

回答by jpp

You can separate into two operations:

您可以分为两种操作:

# dask operation
raw_data = raw_data.drop('some_great_column', axis=1)

# conversion to pandas
df = raw_data.compute()

Then export the Pandas dataframe to a CSV file:

然后将 Pandas 数据框导出到 CSV 文件:

df.to_csv(r'out.csv', index=False)