1

I am having problem in unpickling a .pkl file and editing it. I tried the following code but it shows error. How could I proceed?

import pickle
import numpy as np

with open('speech_emotion_data.pkl', 'rb') as pickle_file:
    new_data = pickle.load(pickle_file)

it shows error as:

UnpicklingError: invalid load key, '\x1f'.

Anindita
  • 69
  • 1
  • 2
  • 7
  • Possible duplicate of [Unable to load CIFAR-10 dataset: Invalid load key '\x1f'](https://stackoverflow.com/questions/45121556/unable-to-load-cifar-10-dataset-invalid-load-key-x1f) – snakecharmerb May 15 '19 at 07:32
  • See also https://stackoverflow.com/questions/33049688/what-causes-the-error-pickle-unpicklingerror-invalid-load-key – snakecharmerb May 15 '19 at 07:32

1 Answers1

1

I was having the same problem, it seems that Pickle files have some troubles when compressed. A temporal solution I found here, adding the following:

gzip or xz as parameters to pd.read_pickle function, or, as in your case, using gzip.open

import gzip
with gzip.open('speech_emotion_data.pkl', 'rb') as pickle_file: