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' ```
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
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__)
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.
Related
I can't seem to run this code in python 3.7.7
import panda as pd
all_data = pd.read_csv('gas_prices.csv')
print(all_data)
Traceback (most recent call last):
File "c:/Users/HP/Desktop/VSc Code/Understanding pand/Sales_analysis/sale_data.py", line 1, in <module>
import panda as pd
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\site-packages\panda\__init__.py", line 1, in <module>
from request import PandaRequest
ModuleNotFoundError: No module named 'request'
I try to change the interpreter but it doesn't seem to make a difference and I don't think I'm in a virtual environment.
This was working a few days ago but suddenly this error started appearing.
accourding to pypi use : pip install request
You've manually installed part of pandas and accidentally named it "panda". Instead use the tool pip, which in Python 3.7.7 is included. Like so:
C:\> C:\Users\HP\AppData\Local\Programs\Python\Python37\Scripts\pip.exe install pandas
Good luck!
I am watching this tutorial where I am trying to use iexfinance to get stock data. You have the option to choose the data type when requesting the data, I chose "pandas". When I run the built-in function I get an error that reads AttributeError: module 'pandas.compat' has no attribute 'string_types'
I am using python 3.7. I have uninstalled and reinstalled both iexfinance and pandas. I also created and IEX cloud account and passed in a secret key like the documentation states, but the same error. The tutorial doesn't mention any of these steps and its confusing why his works and mine isn't.
I have tried to make the code simpler by following examples on the website: Even when running:
from iexfinance.stocks import Stock
df = Stock("AAPL", output_format="pandas")
print(df.get_quote().head())
The error persists
The expected output is:
AAPL
avgTotalVolume 30578248
calculationPrice close
change -0.58
changePercent -0.00298
close 207.27
The output I am receiving is:
Traceback (most recent call last):
File "app.py", line 18, in <module>
df = Stock("AAPL", output_format="pandas")
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/iexfinance/stocks/base.py", line 45, in __init__
self.symbols = list(map(lambda x: x.upper(), _handle_lists(symbols)))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/iexfinance/utils/__init__.py", line 43, in _handle_lists
if isinstance(l, (compat.string_types, int)):
AttributeError: module 'pandas.compat' has no attribute 'string_types'
You can try reverting the pandas version to 0.24.2 as a workaround:
pip install pandas==0.24.2
At this point I am still not sure if a bug in pandas or something else.
EDIT: Probably the iexfinance is using some internals in Pandas, and pandas has undergone a major change dropping python 2 and all the compatibility code.
This is also already on their issue tracker:
https://github.com/addisonlynch/iexfinance/issues/163
The method about:
pip install pandas==0.24.2
is right~ try this.
To date 2 October 2019, just update iexfinance to the latest version (0.4.3) and the problem is solved. Do this:
pip install iexfinance --upgrade
I am running Python 2.7.10 on a Macbook.
I have installed:
Homebrew
Python 2.x, 3.x
NI-VISA
pip
pyvisa, pyserial, numpy
PyVISA
Anaconda
Pandas
I am attempting to run this script. A portion of it can be read here:
import visa
import time
import panda
import sys
import os
import numpy
os.system('cls' if os.name == 'nt' else 'clear') #clear screen
rm = visa.ResourceManager()
rm.list_resources()
print(rm.list_resources())
results = panda.DataFrame(columns=['CURR', 'VOLT', 'TIME'])
This is what is returned on the command line, below.
Note the line that says
AttributeError: 'module' object has no attribute 'DataFrame'
(u'USB0::0x05E6::0x2280::4068201::INSTR', u'ASRL1::INSTR', u'ASRL2::INSTR', u'ASRL4::INSTR')
Traceback (most recent call last):
File "k2280.py", line 14, in <module>
results = panda.DataFrame(columns=['CURR', 'VOLT', 'TIME'])
AttributeError: 'module' object has no attribute 'DataFrame'
Any help or insight on this issue would be appreciated.
It's pandas, not panda, so use import pandas instead. It's also common practice to import pandas as pd for convenience:
import pandas as pd
df = pd.DataFrame()
The module is called pandas not panda
python3 -m pip install pandas
import pandas as pd
pd.DataFrame()
Please read if you're new to python.
As I am also new to python since 2 days and going through the tutorial.
What I know is pandas are the packages we install in the python library to the machine we are using.
As I am new and I was practicing to import and use pandas.DataFrame I kept my filename as pandas.py
And here is the error I was doing. I can't use pandas.py because the machine is assuming its module inside this pandas.py
I changed the filename and it start working fine.
Few things to know if you're getting errors.
You are using pandas.py as filename, you need to change the file name
You are not importing pandas in the file and started working on its module
You are not using DataFrame in camel case
I think these 3 things should be kept in mind to use DataFrame to avoid this error.
I want to use the signal processing library under Scipy. But running the following example code given in Scipy webpage has given me an error. I have rechecked my Scipy installation and it is the latest.
The example code I ran is as follows
from scipy import signal
import numpy as nu
b=nu.array([0.5,0.25])
a=nu.array([1.0,-1.0/3])
C=nu.array([[0,1]])
D=nu.array([[0]])
num=[1,3,3]
den=[1,2,1]
sys=signal.TransferFunction(num,den)
print sys
When I ran it, it gives:
$ python trial.py
Traceback (most recent call last):
File "trial.py", line 9, in <module>
sys=signal.TransferFunction(num,den)
AttributeError: 'module' object has no attribute 'TransferFunction'
AttributeError: 'module' object has no attribute 'TransferFunction'
This is the key phrase you want to search based on. Have you tried importing the module explicitly?
Also this could give you more information related to your problem.
Please check the scipy version you have installed, if you have an older version of scipy the TransferFunction might not be there, due to which you are seeing the AttributeError
For me your code worked fine for latest version of scipy
After installing the facebook-sdk module here, and looking at other solutions here and elsewhere, I keep getting this error:
Traceback (most recent call last):
File "facebook.py", line 1, in <module>
import facebook
File "/home/facebook/facebook.py", line 3, in <module>
graph = facebook.GraphAPI(access_token='ACCESS TOKEN HERE')
AttributeError: 'module' object has no attribute 'GraphAPI'
For this very simple python code to authenticate...
import facebook
graph = facebook.GraphAPI(access_token='ACCESS TOKEN HERE')
print 'Workinnnn'
It says my module is installed and up to date, and I have installed both within (as suggested) a virtualenv and outside, and still get the error. I also definitely HAVE the module in usr/local/lib/python etc. dist packages... and it contains the class GraphAPI
Has anyone got a suggestion either:
1) What might be going wrong?
2) What to try to fix it? UNinstall something?
3) If there is another way other than pip to install the module... I don't normally use pip (but definitely have it installed and installed facebook-sdk from it) so if there's another way then I'd like to try...
Cheers :/
Solution = don't name your script the same as your module.
I'm an idiot, sigh...