1

I have a pickled item stored, created 2 years ago, under Python 2 and pandas version<0.17, which I cannot figure how to open. The item contains a dictionary with some pd.DataFrames as values assigned to the keys.

Back then, I was on Windows 7 and I can't remember if I used an encoding different than the predefined.

In Python3, after trying different combinations of open modes ('r','rb') for the file handler, pickle's fix_import=True option and some more solutions I found here, I couldn't figure this out, so I decided to load 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 dataframe in Python2

Now, on to Python 3, I am trying to open it and the following error occurs:

ImportError: No module named 'pandas.indexes'

At this point it is my understanding that I have overcome the encoding issues between Python 2 & 3, but probably something got deprecated from the previous pandas version I was using. My current pandas version on Python 2 is 0.19 and in Python 3 0.20.

Should I load and "update" the dataframes in Python 2 and then jump into Python 3 and how should I do that? I already tried saving the pickle again but no luck.. Is there something else causing the error maybe?

tony.crete
  • 229
  • 2
  • 11
  • Very likely, indeed. – freakish Jun 11 '17 at 21:35
  • 2
    Possible duplicate of [ImportError: No module named 'pandas.indexes'](https://stackoverflow.com/questions/37371451/importerror-no-module-named-pandas-indexes) – DYZ Jun 11 '17 at 21:38
  • 3
    apparently no one reads the docs anymore: simply use pd.read_pickle and this will just work. see the big red box: http://pandas.pydata.org/pandas-docs/stable/io.html#pickling – Jeff Jun 11 '17 at 22:24
  • 1
    Indeed a duplicate. For the record, solution is use: pd.read_pickle('foo.pkl') . Worked for me even when the stored pkl contained a dictionary of pandas dataframes. – ntg Nov 23 '17 at 17:34

0 Answers0