[Solved]-modulenotfounderror: no module named 'pandas.core.indexes.numeric'


"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:

  1. Make sure you have pandas installed in your Python environment. You can install pandas using pip:
  2. pip install pandas
  3. If pandas is already installed, ensure that you are importing it correctly in your Python script:
  4. import pandas as pd
  5. Check if there are any typos in your import statement or if you are using the correct casing.
  6. If you are still encountering the error, it's possible that you are trying to access a module or submodule that does not exist in your version of pandas.
  7. In older versions of pandas, there was a module called pandas.core.indexes.numeric, but it might have been deprecated or removed in newer versions.
  8. Consider checking the pandas documentation or release notes to see if there are any changes related to the module you are trying to import.
  9. If you are working with numeric indexes, you can use alternatives such as pandas.Index or pandas.RangeIndex depending on your requirements.
  10. Update your code to use the appropriate modules and functions available in the version of pandas you are using.
"ModuleNotFoundError: No module named 'pandas.core.indexes.numeric' using Metaflow"

"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""

"ImportError: No module named 'pandas.indexes'"

"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()
'ModuleNotFoundError: No module named 'pandas.core.indexes.numeric''

"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"