首页 > 解决方案 > CSV to Feather in Pandas with slicing Rows

问题描述

我正在处理一个巨大的 CSV 数据集(5000 万行)。我正在尝试对其进行切片并将其保存为羽毛格式,以便在稍后加载羽毛格式时节省一些内存。

作为一种解决方法,我将数据块加载为 CSV 文件,然后将其合并到一个数据框中。

这是我到目前为止所尝试的:

df[2000000:4000000].to_feather('name')

我收到以下错误:

ValueError: feather does not support serializing a non-default index for the index; you can .reset_index() to make the index into column(s)

然后我尝试重置索引,但仍然出现同样的错误。

标签: pythonpandasfeather

解决方案


尝试.loc

df.loc[2000000:4000000].reset_index().to_feather("./myfeather.ftr")

您必须重置索引才能将数据帧保存为羽化格式。为我工作。


推荐阅读