9

I wrote this code to load a dataset into a data frame. Dataset is given in a pickle file but it throws an error:

ModuleNotFoundError: No module named 'pandas.core.indexes'

import pickle
import pandas
dbfile = open(dataset loction,'rb')
df = pickle.load(dbfile)

I tried all the fixes given:

  1. Updated the pandas
  2. used df = pandas.read_picle(dataset location)

Tried installing pickle using pip but getting this error

C:\installs\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64>python -m pip install pickle
Collecting pickle
  Could not find a version that satisfies the requirement pickle (from versions: )
No matching distribution found for pickle
RAMAN BHATIA
  • 397
  • 2
  • 5
  • 17
  • Please provide error details of the code. since its confusing with the title. – jits_on_moon Jul 11 '18 at 12:46
  • This is the complete error i am getting :`ModuleNotFoundError Traceback (most recent call last) in () 2 import pandas 3 dbfile = open(r'C:\Users\raman\Downloads\df_train_api.pk','rb') ----> 4 df = pickle.load(dbfile) 5 6 df ModuleNotFoundError: No module named 'pandas.core.indexes'` – RAMAN BHATIA Jul 11 '18 at 12:49
  • We need to see the real implementation because the line dbfile = open(dataset loction,'rb') makes no sense and we can't tell if that's the source of error or if it's properly implemented – Yuca Jul 11 '18 at 12:50
  • I have a dataset named **df_train_api.pk** that is stored in my downloads folder, I am using this specific code: `import pickle import pandas dbfile = open(r'C:\Users\raman\Downloads\df_train_api.pk','rb') df = pickle.load(dbfile) df` – RAMAN BHATIA Jul 11 '18 at 12:52

3 Answers3

14

That smells like the pickle file has been created with a different version of Pandas, and your currently installed Pandas doesn't have the pandas.core.indexes module that some of the data in the pickle requires.

Which version of Pandas are you using? Have you tried upgrading?

EDIT: Pandas 0.19.2 does not have that module:

$ pip install pandas==0.23.3
$ python
>>> import pandas.core.indexes as i
>>>
$ pip install pandas==0.19.2
$ python
>>> import pandas.core.indexes as i
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas.core.indexes'
>>>
AKX
  • 152,115
  • 15
  • 115
  • 172
1

I would suggest using pandas pickle method to read .pk file.

import _pickle as cPickle
with open('filename.pkl', 'rb') as fo:
        dict = cPickle.load(fo, encoding='latin1’)

see doc here. Pickle Read

jits_on_moon
  • 827
  • 6
  • 10
  • I tried using this code `pandas.read_pickle(r'C:\Users\raman\Downloads\df_train_api.pk')` it also throws the same **ModuleNotFoundError: No module named 'pandas.core.indexes'** – RAMAN BHATIA Jul 11 '18 at 12:58
  • from which version of python your .pk file is created? also need to know your encoding method. – jits_on_moon Jul 11 '18 at 13:01
  • I don't have an idea about that, will it matter I am using python3.6 as of now. This is a part of interview assignment I got to complete. – RAMAN BHATIA Jul 11 '18 at 13:03
  • 2
    it does matter if your pickle file is created with lower python version. like 2.7 – jits_on_moon Jul 11 '18 at 13:04
  • Any fix for that matter as I am not sure if I can contact them now I have a deadline for tomorrow. – RAMAN BHATIA Jul 11 '18 at 13:05
  • can't suggest without knowing pickle file meta data. try from above answer code just updated. this is lower C level implementation of pickle. – jits_on_moon Jul 11 '18 at 13:06
  • also if you can locate this file in python installation that would be great to know about missing module. under python installation site-package/pandas/core index.py – jits_on_moon Jul 11 '18 at 13:08
1

The answer by @AKX made me realise that it was probably a version problem Pandas. However, I only needed to upgrade.

pip install pandas --upgrade
ojunk
  • 879
  • 8
  • 21