"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'
To resolve the "ModuleNotFoundError: No module named 'pandas.core.indexes.numeric'" error, you can follow these steps:
pip install pandas
import pandas as pd
pandas.core.indexes.numeric
, but it might have been deprecated or removed in newer versions.pandas.Index
or pandas.RangeIndex
depending on your requirements."This issue is caused by the new Pandas 2.0.0 release breaking backwards compatibility with Pandas 1.x, although I don't see this documented in the release notes. The solution is to downgrade pandas to the 1.x series: pip install "pandas<2.0.0""
"I had this error when I created a pkl file with Python 2.7 and was trying to read it with Python 3.6. I did:
pd.read_pickle('foo.pkl')
"A flexible way to deal with internal API changes that break unpickling is to implement a custom Unpickler instance.
For example, the pandas.indexes module has been moved to pandas.core.indexes. We can write an Unpickler that adapts the module path accordingly. To do that, we can overwrite the method find_class:
import sys
class Unpickler(pickle.Unpickler):
def find_class(self, module, name):
'''This method gets called for every module pickle tries to load.'''
# python 2 --> 3 compatibility: __builtin__ has been renamed to builtins
if module == '__builtin__':
module = 'builtins'
# pandas compatibility: in newer versions, pandas.indexes has been moved to pandas.core.indexes
if 'pandas.indexes' in module:
module = module.replace('pandas.indexes', 'pandas.core.indexes')
__import__(module)
return getattr(sys.modules[module], name)
with open('/path/to/pickle.pkl', 'rb') as file:
pdf = Unpickler(file).load()
"It was actually an error with the pandas version.
By installing an older pandas version, the issue was resolved:
pip install "pandas<2.0.0"