scipy.stats ImportError: cannot import name 'alexandergovern' - python

I am trying to apply scipy's Alexander Govern test:
import pandas as pd
import scipy.stats
df1 = pd.read_csv(r'Data1.tsv', sep='\t', encoding='utf-8')
df2 = pd.read_csv(r'Data2.tsv', sep='\t', encoding='utf-8')
from scipy.stats import alexandergovern
alexandergovernTest = alexandergovern(df1.iloc[2:,:135], df2.iloc[2:,:134])
print(alexandergovernTest)
I get the following error:
Traceback (most recent call last):
File "calculate_onewayANOVA.py", line 41, in <module>
from scipy.stats import alexandergovern
ImportError: cannot import name 'alexandergovern'

This error is resolved after upgrading to python3.8 in Ubuntu 20 and installing scipy==1.7.3, as indicated by #Nelewout and #WarrenWeckesser

Related

AttributeError: 'SearchEngine' object has no attribute 'ses'

I am trying to use the zipcodes package but was getting a ses error. Here is a brief snippt of my code.
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()
import geopandas as gpd
import requests
import zipfile
import io
import os
import pyproj
from shapely.ops import transform
from functools import partial
import json
from uszipcode import SearchEngine
search = SearchEngine(simple_zipcode=True)
I am getting the following error
Exception ignored in: <function SearchEngine.__del__ at 0x7fcd6087eca0>
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.8/site-packages/uszipcode/search.py", line 195, in __del__
if self.ses:
AttributeError: 'SearchEngine' object has no attribute 'ses'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-35-325ac6f8df7d> in <module>
----> 1 search = SearchEngine(simple_zipcode=True)
2 search.ses.scalar(SimpleZipcode)
TypeError: __init__() got an unexpected keyword argument 'simple_zipcode'
Any pointers?

unable to import pandas in jupyter

When I import pandas in jupyter library the following is generated.
AttributeError Traceback (most recent call last)
<ipython-input-24-f869c0f42cc0> in <module>
----> 1 import pandas as pd
2 import numpy as np
3 get_ipython().run_line_magic('matplotlib', 'inline')
C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py in <module>
24
25 try:
---> 26 from pandas._libs import (hashtable as _hashtable,
27 lib as _lib,
28 tslib as _tslib)
pandas\_libs\hashtable_class_helper.pxi in init pandas._libs.hashtable()
AttributeError: type object 'pandas._libs.hashtable.HashTable' has no attribute '__reduce_cython__'
Can you help me in figuring out the problem? Thanks
Use pd at the place of pandas in your code. If you still get error, then write your code also in the question.

AttributeError: '_process_plot_var_args' object has no attribute 'get_next_color'

I have tried to run the following code. but it gives an argument required error in lifelines/plotting.py file. i can't fix it .
import pandas as pd
from lifelines.datasets import load_dd
import matplotlib.pyplot as plt
data = load_dd()
print data.sample(6)
from lifelines import KaplanMeierFitter
kmf = KaplanMeierFitter()
T = data["duration"]
E = data["observed"]
kmf.fit(T, event_observed=E)
kmf.survival_function_.plot()
plt.title('Survival function of political regimes');
kmf.plot()
plt.show()
but it gives the following error
Traceback (most recent call last): File "/Users/rabindra/PycharmProjects/SurvivalAnalysis/sources/main.py", line 17, in <module>
kmf.plot() File "/Library/Python/2.7/site-packages/lifelines/plotting.py", line 331, in plot
set_kwargs_color(kwargs) File "/Library/Python/2.7/site-packages/lifelines/plotting.py", line 223, in set_kwargs_color
kwargs["ax"]._get_lines.get_next_color()) AttributeError: '_process_plot_var_args' object has no attribute 'get_next_color'
I was facing the same issue.
Upgraded lifelines to 0.14.0 and matplotlib to 2.2.2 and it works.

"Import Error: cannot import name 'unicode_literals' "

Sorry if this is a dumb question but I'm trying to import and open a CSV using pandas in Python. Whenever I hit run I get the syntax error "cannot import name 'unicode_literals'". I have no idea why that is happening and I haven't been able to find any source online which details what this error means.
This is my code:
import pandas as pd
with open(r"FILEPATH\File.csv") as rawData:
pd.read_csv(rawData)
Here is the Error:
C:\Anaconda3\python.exe "FILEPATH"
Traceback (most recent call last):
File "FILEPATH/Main.py", line 1, in <module>
import pandas as pd
File "C:\Anaconda3\lib\site-packages\pandas\__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
File "pandas\src\numpy.pxd", line 157, in init pandas.hashtable (pandas\hashtable.c:22997)
File "C:\Anaconda3\lib\site-packages\numpy\__init__.py", line 107, in <module>
from __future__ import division, absolute_import, print_function
File "C:\Anaconda3\lib\__future__.py", line 23, in <module>
from __future__ import unicode_literals
ImportError: cannot import name 'unicode_literals'
cannot import name 'unicode_literals'
Any suggestions for why this isn't working would be greatly appreciated.
You're on the right track! The only thing you have to do is add another parameter to open(). This would yield:
import pandas as pd
with open(r"FILEPATH\File.csv", encoding='utf-8') as rawData:
pd.read_csv(rawData)

Why is my Python program throwing an exception depending on the name of the file?

I'm just learning Python.
I have a file with the following content
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
If I name this file csv2.py and call:
python csv2.py
... it works. But if I name this file csv.py and run:
python csv.py
It triggers this exception:
C:\Git\algotrading [master ≡ +3 ~0 -0 !]> python csv.py
Traceback (most recent call last):
File "csv.py", line 2, in <module>
import matplotlib.pyplot as plt
File "C:\Users\andrerpena\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\pyplot.py", line 29, in <module>
import matplotlib.colorbar
File "C:\Users\andrerpena\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "C:\Users\andrerpena\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\collections.py", line 36, in <module>
import matplotlib.mlab as mlab
File "C:\Users\andrerpena\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\mlab.py", line 172, in <module>
import csv
File "C:\Git\algotrading\csv.py", line 2, in <module>
import matplotlib.pyplot as plt
AttributeError: module 'matplotlib' has no attribute 'pyplot'
It took me like 40 minutes to figure out the problem. I mean.. Figure out the problem had to do with the name of the file.
Why is that happening?
It looks like matplotlib.pyplot through various imports needs mlab.py which calls "import csv". This should find a file (that is not yours) called csv but since you have renamed your file to csv.py it is attempting to import that instead, overriding the required import and messing up the import for matplotlib.pyplot.
csv.py is built into python and thus is restricted.
If you run a python interpreter and try to import csv, you'll succeed without having to download anything new.
Like igoldthwaite and Daniel Dobalian said:
If you create a file named: csv.py with the content:
import csv
print(csv)
And run:
python csv.py
You will see that this file import itself:
<module 'csv' from '/home/your/folder/csv.py'>
Also, if you do the same thing with other modules, you will find the same result:
import subprocess
print(subprocess)
Result:
<module 'subprocess' from '/home/your/folder/subprocess.py'>
And finally, if you do it with a file named matplotlib.py, you will get the same result:
import matplotlib
print(matplotlib)
# <module 'matplotlib' from '/home/your/folder/matplotlib.py'>

Categories