ValueError: unsupported pickle protocol: 4 with pandas

ValueError: unsupported pickle protocol: 4 with pandas

我收到这个错误

ValueError: unsupported pickle protocol: 4

来自我的这行代码

full_df = pd.read_pickle('df_userID.pickle')

当 运行 脚本带有 python2.7

(关于 Ubuntu 14.04.5、3.13.0-95-通用)

感谢您的帮助。

看起来这个 pickle 文件的创建如下:

pickle.dump(df, file_name, protocol=4)

pickle.dump(df, file_name, protocol=-1)

和 Python 2.x 仅接受协议:0、1、2

解法:

使用 Pandas 酸洗或较低的协议版本:

df.to_pickle('/path/to/df.pickle')  # preferred and version independent solution

或:

pickle.dump(df, '/path/to/df.pickle', protocol=2)

另一种选择是使用 HDFStore (H5) 或 FeatherFormat - 这两种选择都非常快速且可靠。