pandas ValueError:不受支持的泡菜协议:4 与熊猫

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

ValueError: unsupported pickle protocol: 4 with pandas

pythonpython-2.7pandaspickle

提问by jjrr

I get this error

我收到这个错误

ValueError: unsupported pickle protocol: 4

from this line of my code

从这行我的代码

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

when running the script with python2.7

使用python2.7运行脚本时

(on Ubuntu 14.04.5, 3.13.0-95-generic)

(在 Ubuntu 14.04.5、3.13.0-95-generic 上)

Thanks for help.

感谢帮助。

回答by MaxU

It looks like this pickle file has been created like as follows:

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

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

or

或者

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

and Python 2.x accepts only protocols: 0, 1, 2

和 Python 2.x 只接受协议:0, 1, 2

Solution:

解决方案:

either use Pandas pickling or a lower protocol version:

要么使用 Pandas 酸洗,要么使用较低的协议版本:

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

or:

或者:

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

another option would be to use HDFStore (H5) or FeatherFormat - both options are very fast and reliable.

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