Im trying to use the following code (example):
import pandas as pd
(import statsmodels.api as sm) - Tried adding, no luck
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
x = pd.DataFrame(imports a vector)
plot_acf(x)
There is some code in between, but the problem arises when Python tries to plot the autocorrelation using statsmodels, and returns the following error:
File "/Users/user/anaconda/lib/python3.6/site-packages/statsmodels/iolib/foreign.py",
line 20, in <module>
import statsmodels.tools.data as data_util
AttributeError: module 'statsmodels' has no attribute 'tools'
I tried reinstalling multiple libraries, but nothing seems to get me past this error. Could this be a statsmodels-side bug?
Related
I am trying to to use the pandas profiling for profile report. I got the error "module' object is not callable. How can I fix in Jupyter notebook from Anaconda.
My code:
import pandas as pd
import pandas_profiling
df = pd.read_csv(r'C:\Users\tai.phan\Desktop\Pythone training\Data\titanic.csv')
pandas_profiling.profile_report(df)
The error:
TypeError: 'module' object is not callable
pandas_profiling isn't a function
import pandas as pd
import pandas_profiling.profile_report as report
df = pd.read_csv(r'C:\Users\tai.phan\Desktop\Pythone training\Data\titanic.csv')
report.whateverfunctionyouwant(df)
look at the documentation to understand this module more
https://pandas-profiling.github.io/pandas-profiling/docs/master/index.html
you can also select a function from the following list of functions for profile_report
clear_config
description_set
df_hash
get_description
get_duplicates
get_rejected_variables
get_sample
html
json
preprocess
report
set_variable
set_variables
title
to_app
to_file
to_html
to_json
to_notebook_iframe
to_widgets
widgets
try df.profile_report() worked for me
I am trying to run some code on a spark kubernetes cluster
"spark.kubernetes.container.image", "kublr/spark-py:2.4.0-hadoop-2.6"
The code I am trying to run is the following
def getMax(row, subtract):
'''
getMax takes two parameters -
row: array with parameters
subtract: normal value of the parameter
It outputs the value most distant from the normal
'''
try:
row = np.array(row)
out = row[np.argmax(row-subtract)]
except ValueError:
return None
return out.item()
from pyspark.sql.types import FloatType
udf_getMax = F.udf(getMax, FloatType())
The dataframe I am passing is as below
However I am getting the following error
ModuleNotFoundError: No module named 'numpy'
When I did a stackoverflow serach I could find similar issue of numpy import error in spark in yarn.
ImportError: No module named numpy on spark workers
And the crazy part is I am able to import numpy outside and
import numpy as np
command outside the function is not getting any errors.
Why is this happening? How to fix this or how to go forward. Any help is appreciated.
Thank you
I want to write a program which performs a periodogram on a series of measurement values listed in the file 'flux.txt' but I get the error:
module 'numpy' has no attribute 'testing'
The error also appears if I comment the whole code. I tried to update numpy but it's still updated. May someone help me please?
from scipy import signal
import numpy as np
import matplotlib.pyplot as plt
with open('flux.txt','r') as f:
item = f.readlines
print(item)
signal.periodogram(item)
plt.show()
I tried two different import syntaxes I thought were equivalent. Weirdness seems to ensue:
In [7]: import sympy
In [8]:sympy.physics.units.find_unit("Giga Electron Volt")
Traceback (most recent call last):
File "<ipython-input-8-8a26ac4a085a>", line 1, in <module>
sympy.physics.units.find_unit("Giga Electron Volt")
AttributeError: 'module' object has no attribute 'physics'
In [9]:import sympy.physics.units as u
In [10]:u.find_unit("coul")
Out[10]: ['coulomb', 'coulombs']
In [11]:import sympy
In [12]:sympy.physics.units.find_unit("coul")
Out[12]: ['coulomb', 'coulombs']
Take a look at the source code of sympy here: https://github.com/sympy/sympy/blob/master/sympy/init.py#L55
from .calculus import *
# Adds about .04-.05 seconds of import time
# from combinatorics import *
# This module is slow to import:
#from physics import units
from .plotting import plot, textplot, plot_backends, plot_implicit
They are not importing the physics module, because it takes obviously quite some time to load. This is why you get the error in the first try.
After loading it manually, the interpreter has it loaded and knows where it is (from your manual import). Thats why it works on the second try.
So the phenomenon is not regarded to python import functionality, but to the module initialization.
P.S.
If you uncomment the line that loads unit from the physics module, it would be
import sympy
sympy.units.find_unit("coul")
I am trying to get the beta and the error term from a linear regression(OLS) in python. I am stuck at the statement X=sm.add_constant(X, prepend=True), which is returning an
error:"AttributeError: 'module' object has no attribute 'add_constant'"
I already installed the statsmodels module.
Try importing statsmodel.api
import statsmodels.api as sm
Try importing add_constant, for example:
from statsmodels.api import add_constant
If sm is a defined object in statsmodels, you need to invoke it by statsmodels.sm, or using from statsmodel import sm, then you can invoke sm directly.