use*_*588 5 pickle dataframe pandas
有一个关于 Pandas DataFrame 和 pd.read_pickle() 函数的快速问题。基本上,我有一个大而简单的数据框(333 mb)。当我在数据帧上运行 pd.read_pickle 时,我得到了 EOFError。
有没有办法解决这个问题?你知道是什么原因造成的吗?
谢谢!
小智 0
当我使用以下命令创建 pickle 时,我看到了相同的 EOFError:
\n\npandas.DataFrame.to_pickle('path.pkl', compression='bz2')\nRun Code Online (Sandbox Code Playgroud)\n\n然后尝试阅读:
\n\npandas.read_pickle('path.pkl')\nRun Code Online (Sandbox Code Playgroud)\n\n我通过提供读取压缩解决了这个问题:
\n\npandas.read_pickle('path.pkl', compression='bz2')\nRun Code Online (Sandbox Code Playgroud)\n\n根据 Pandas 文档:
\n\ncompression : {\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.\nRun Code Online (Sandbox Code Playgroud)\n\n因此,只需将路径从“path.pkl”更改为“path.bz2”也可以解决该问题。
\n