4

I am trying to import pandas-ml but I get this import error. What might be the issue?

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-fd3c3c034481> in <module>
----> 1 import pandas_ml as pml

AttributeError: module 'pandas.compat' has no attribute 'iteritems' ```


Mert Köklü
  • 2,183
  • 2
  • 16
  • 20
kongkip
  • 61
  • 1
  • 7

3 Answers3

1
File "/usr/local/lib/python3.7/site-packages/pandas_ml/core/accessor.py", line 81, in _update_method_mapper
    for key, class_dict in compat.iteritems(cls._method_mapper):
AttributeError: module 'pandas.compat' has no attribute 'iteritems'

I have the same error too with python3.7. I solved it with changing iteritems() to items() .

There are two lines on accessor.py under @classmethod, change them into:

 for key, class_dict in cls._method_mapper.items():
'
'
'
      class_dict = {k: getattr(cls, m) for k, m in class_dict.items()}

For my version, I have also encounter another import error ImportError: cannot import name 'range' from 'pandas.compat'in File "/usr/local/lib/python3.7/site-packages/pandas_ml/confusion_matrix/stats.py". just delete from pandas.compat import range would do.

Reference:

https://github.com/pandas-dev/pandas/commit/e26e2dfe6e93922830fb5fb7868b87238b85911a#diff-21f71fbdb0d3dfa55dc948e2ddcddc92

chrisckwong821
  • 1,133
  • 12
  • 24
  • @kongkip If my answer was helpful, pls accept it - click on the check mark (✓) beside the answer to toggle it from greyed out to filler in. Thanks. – chrisckwong821 Oct 23 '19 at 16:47
0

The iteritems attribute for pandas.compat appears to be have been removed recently, as seen here (tip from this source).

In other words, your current version of pandas is incompatible with pandas-ml currently.

The GitHub issue suggests to maybe downgrade your pandas version.

# Installed using pip
pip install pandas==0.24.2

# Installed using conda
conda install pandas==0.24.2

You can run the following in the Python REPL to double check the pandas package version to see if it is greater than 0.25.0.

import pandas

print(pandas.__version__)
Eric Leung
  • 2,354
  • 12
  • 25
  • This is not work in my case. I was running pandas 0.25.1, and got the same error as the original post, then downgraded to pandas 0.24.2, but the error persists. – Edward Mar 05 '20 at 14:09
0

I had the same problem. I found out, that pandas_ml is not compatible with the current verions of scikit-learn and pandas. So I wrote a fix and made a pull request on github. Have a look here https://github.com/AlfredoCubitos/pandas-ml or here https://github.com/pandas-ml/pandas-ml/pull/132.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Alfredo cubitos
  • 161
  • 2
  • 5