简体   繁体   中英

ValueError: unsupported pickle protocol: 4 with pandas

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

(on Ubuntu 14.04.5, 3.13.0-95-generic)

Thanks for help.

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

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

Solution:

either use Pandas pickling or a lower protocol version:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM