Unable to open pickled DataFrames dictionary from previous version of Python / pandas

I have a pickled item stored 2 years ago under Python 2and pandas version<0.17that I can’t understand how to open it. The element contains a dictionary with some pd.DataFrames parameters as the values ​​assigned to the keys.

I was in Windows 7 at that time, and I can’t remember if I used a different encoding than the predefined one.

In Python3, after checking various combinations of open modes ('r','rb')for the file handler, pickle option fix_import=Trueand some other solutions that I found here, I couldn’t figure it out, so I decided to upload the file again in Python 2 and save it using the following code:

with open(path, 'rb') as handle:
  cons = pickle.load(handle)
with open('cons.pickle','wb') as f:
    pickle.dump(cons,f)

Also note that I can normally access the data framework in Python2

Now, in Python 3, I try to open it, and the following error occurs:

ImportError: no module named pandas.indexes

At this point, I understand that I have overcome the encoding problems between Python 2 and 3, but probably something is deprecated from the previous version of pandas that I used. My current version of pandas is in Python 2 - 0.19and in Python 3 0.20.

Should I load and “update” data frames in Python 2, and then migrate to Python 3 and how do I do this? I already tried to save the pickle again, but no luck .. Is there anything else causing the error, maybe?

+1
source share

Source: https://habr.com/ru/post/1686932/


All Articles