这里是python的新手。
使用以下内容: Anaconda - v1.3.1 Spyder - v3.1.4 Python - v3.5
我正在尝试导入以下库:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import statsmodels.formula.api as sm
它一直给我以下错误:
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'
我读了一些关于更新熊猫的帖子。我试过了,但它没有用。关于错误和解决方案的任何想法? (当我只导入statsmodel.formula或只是statsmodel时,它工作正常)
答案 0 :(得分:15)
升级statsmodel对我有用,
create table test (employee integer NOT NULL, code character varying(200), number integer)
insert into test(employee, code, number ) values(17,'bangalore',(select coalesce(max(number) + 1,1) from test where employee = 17 and code = 'bangalore'));
insert into test(employee, code, number ) values(17,'bangalore',(select coalesce(max(number) + 1,1) from test where employee = 17 and code = 'bangalore'));
insert into test(employee, code, number ) values(17,'mumbai',(select coalesce(max(number) + 1,1) from test where employee = 17 and code = 'mumbai'));
答案 1 :(得分:1)
对于 python3 :
您需要升级statsmodels。如果有问题,请使用特定版本,例如:
py -m pip install statsmodels==0.6.0
然后您就可以使用
py -m pip install statsmodels --upgrade
答案 2 :(得分:0)
在处理Azure数据块时,上述解决方案对我而言并不奏效。但是有一件事情对我有用,我不确定为什么。因此,当我重新启动笔记本电脑并按以下所列进行导入时,它可以正常工作。请评论这是否对您有用,以及如果您可能知道为什么它起作用。
import statsmodels
import statsmodels.api as sm
import statsmodels.formula.api as smf
答案 3 :(得分:0)
使用此
将statsmodels.api导入为sm