statsmodels.formula.api importError: cannot import name 'TimeSeries'
Asked Answered
E

4

7

New to python here.

Using the following: Anaconda - v1.3.1 Spyder - v3.1.4 Python - v3.5

I am trying to import the following libraries:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import statsmodels.formula.api as sm

It keeps giving me the following error:

import statsmodels.formula.api as sm
Traceback (most recent call last):

  File "<ipython-input-2-2515cefb61aa>", line 1, in <module>
    import statsmodels.formula.api as sm

  File "//anaconda/lib/python3.5/site-packages/statsmodels/formula/api.py", line 1, in <module>
    from statsmodels.regression.linear_model import GLS

  File "//anaconda/lib/python3.5/site-packages/statsmodels/regression/__init__.py", line 1, in <module>
    from .linear_model import yule_walker

  File "//anaconda/lib/python3.5/site-packages/statsmodels/regression/linear_model.py", line 52, in <module>
    import statsmodels.base.model as base

  File "//anaconda/lib/python3.5/site-packages/statsmodels/base/model.py", line 5, in <module>
    from statsmodels.base.data import handle_data

  File "//anaconda/lib/python3.5/site-packages/statsmodels/base/data.py", line 8, in <module>
    from pandas import DataFrame, Series, TimeSeries, isnull

ImportError: cannot import name 'TimeSeries'

I read some posts about updating pandas. I tried that but it doesn't work. Any ideas as to the error and a solution? (It works fine when I import only statsmodel.formula or just statsmodel)

Elgin answered 1/6, 2017 at 16:35 Comment(1)
What happens when you do from pandas import TimeSeries ?Agro
F
2

For python3:

You need to upgrade statsmodels. If that is a problem go for a specific version such as:

py -m pip install statsmodels==0.6.0

Then you can use

py -m pip install statsmodels --upgrade

For python2.x

pip install statsmodels --upgrade

Fabliau answered 5/12, 2018 at 5:17 Comment(0)
S
16

Upgrading statsmodels worked for me,

pip install statsmodels --upgrade

Stryker answered 2/6, 2017 at 7:16 Comment(2)
conda upgrade statsmodels might be preferable if using Anaconda, for future version compatibilityPropaedeutic
Restart kernel if using Jupyter notebooks after the upgrade.Honea
F
2

For python3:

You need to upgrade statsmodels. If that is a problem go for a specific version such as:

py -m pip install statsmodels==0.6.0

Then you can use

py -m pip install statsmodels --upgrade

For python2.x

pip install statsmodels --upgrade

Fabliau answered 5/12, 2018 at 5:17 Comment(0)
C
1

The above solutions didn't quite worked for me when working on azure databricks. But one thing worked for me, which I am not sure why. So when I restarted my notebook and imported as listed below it worked. Please comment if this worked for you and also in case you may have any idea why this worked.

    import statsmodels
    import statsmodels.api as sm
    import statsmodels.formula.api as smf
Creep answered 9/1, 2019 at 11:17 Comment(0)
J
0

Use this

import statsmodels.api as sm

Jehiel answered 8/2, 2020 at 7:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.