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
ValueError: unsupported pickle protocol: 4 with pandas
提问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 - 这两个选项都非常快速和可靠。