8

I'm reading a pickle file with:

pandas.read_pickle('data/file.pickle')

and it throws this error:

UnpicklingError: invalid load key, '\x00'.

Note that I've seen other threads on how to solve this problem when saving the pickle file, but in my case I just need to open this specific dataframe.

Also the pickle file could contain some special characters.

Monica Heddneck
  • 2,973
  • 10
  • 55
  • 89
Henrique Nader
  • 269
  • 2
  • 11

1 Answers1

7

One of the possible explanation is pickling with compression. On my system, reading files compressed with either xz or gzip throws exception of invalid load key if I do not specify compression. In similar case, both zip and bz2 raise different exceptions.

I recommend to try one of those:

pandas.read_pickle('data/file.pickle', 'xz')
pandas.read_pickle('data/file.pickle', 'gzip')
heavelock
  • 364
  • 4
  • 9
  • Extremely helpful answer :) Solved our problem right away. Saved us some lines of code too, since our target is a Pandas DataFrame anyways. Thanks! – Aaron Bell Jul 27 '22 at 14:18