Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 541
jjrr Avatar asked Jan 29 '17 11:01

jjrr


1 Answers

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.

like image 144
MaxU - stop WAR against UA Avatar answered Oct 17 '22 00:10

MaxU - stop WAR against UA