Python Forum

Full Version: Unable to import statsmodel
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear All,

I am new to python. I would like to replicate some code. The preamble starts as follows:

import numpy as np
from numpy import exp
import matplotlib.pyplot as plt
%matplotlib inline
from scipy.special import factorial
import pandas as pd
from mpl_toolkits.mplot3d import Axes3D
import statsmodels.api as sm
from statsmodels.api import Poisson
from scipy import stats
from scipy.stats import norm
from statsmodels.iolib.summary2 import summary_col
However, it returns the following error:

Error:
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) C:\Anaconda3\lib\site-packages\statsmodels\compat\pandas.py in <module>() 52 try: ---> 53 import pandas.tseries.tools as datetools 54 import pandas.tseries.frequencies as frequencies ModuleNotFoundError: No module named 'pandas.tseries.tools' During handling of the above exception, another exception occurred: ImportError Traceback (most recent call last) <ipython-input-1-3fce8627775d> in <module>() 6 import pandas as pd 7 from mpl_toolkits.mplot3d import Axes3D ----> 8 import statsmodels.api as sm 9 from statsmodels.api import Poisson 10 from scipy import stats C:\Anaconda3\lib\site-packages\statsmodels\api.py in <module>() 5 from . import regression 6 from .regression.linear_model import OLS, GLS, WLS, GLSAR ----> 7 from .regression.recursive_ls import RecursiveLS 8 from .regression.quantile_regression import QuantReg 9 from .regression.mixed_linear_model import MixedLM C:\Anaconda3\lib\site-packages\statsmodels\regression\recursive_ls.py in <module>() 14 from statsmodels.regression.linear_model import OLS 15 from statsmodels.tools.data import _is_using_pandas ---> 16 from statsmodels.tsa.statespace.mlemodel import ( 17 MLEModel, MLEResults, MLEResultsWrapper) 18 from statsmodels.tools.tools import Bunch C:\Anaconda3\lib\site-packages\statsmodels\tsa\statespace\mlemodel.py in <module>() 15 from .kalman_filter import (KalmanFilter, FilterResults, INVERT_UNIVARIATE, 16 SOLVE_LU) ---> 17 import statsmodels.tsa.base.tsa_model as tsbase 18 import statsmodels.base.wrapper as wrap 19 from statsmodels.tools.numdiff import (_get_epsilon, approx_hess_cs, C:\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py in <module>() 1 from statsmodels.compat.python import lrange, long ----> 2 from statsmodels.compat.pandas import is_numeric_dtype 3 4 import datetime 5 C:\Anaconda3\lib\site-packages\statsmodels\compat\pandas.py in <module>() 54 import pandas.tseries.frequencies as frequencies 55 except ImportError: ---> 56 from pandas.core import datetools 57 frequencies = datetools ImportError: cannot import name 'datetools'
I deleted everything from conda and reinstalled but the same error persists. Thank you in advance for your help.

Best,
Sam
How old is the code you are trying to replicate? Are the versions of your modules sufficient.

"pandas.core.datetools" module was removed in early 2019, January i think.(GH14105, GH14094)

And has been deprecated since 2016.