EOF 错误 pd.read_pickle

use*_*588 5 pickle dataframe pandas

有一个关于 Pandas DataFrame 和 pd.read_pickle() 函数的快速问题。基本上,我有一个大而简单的数据框(333 mb)。当我在数据帧上运行 pd.read_pickle 时,我得到了 EOFError。

有没有办法解决这个问题?你知道是什么原因造成的吗?

谢谢!

小智 0

当我使用以下命令创建 pickle 时,我看到了相同的 EOFError:

\n\n
pandas.DataFrame.to_pickle('path.pkl', compression='bz2')\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后尝试阅读:

\n\n
pandas.read_pickle('path.pkl')\n
Run Code Online (Sandbox Code Playgroud)\n\n

我通过提供读取压缩解决了这个问题:

\n\n
pandas.read_pickle('path.pkl', compression='bz2')\n
Run Code Online (Sandbox Code Playgroud)\n\n

根据 Pandas 文档:

\n\n
compression : {\xe2\x80\x98infer\xe2\x80\x99, \xe2\x80\x98gzip\xe2\x80\x99, \xe2\x80\x98bz2\xe2\x80\x99, \xe2\x80\x98zip\xe2\x80\x99, \xe2\x80\x98xz\xe2\x80\x99, None}, default \xe2\x80\x98infer\xe2\x80\x99\n\n    string representing the compression to use in the output file. By default, \n    infers from the file extension in specified path.\n
Run Code Online (Sandbox Code Playgroud)\n\n

因此,只需将路径从“path.pkl”更改为“path.bz2”也可以解决该问题。

\n