Python Statsmodels x13_arima_analysis:AttributeError:'dict'对象没有属性'iteritems' [英] Python Statsmodels x13_arima_analysis : AttributeError: 'dict' object has no attribute 'iteritems'

查看:96
本文介绍了Python Statsmodels x13_arima_analysis:AttributeError:'dict'对象没有属性'iteritems'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第 1 步:我的示例数据

将pandas导入为pd从熊猫进口时间戳s = pd.Series({时间戳('2013-03-01 00:00:00'):838.2,时间戳('2013-04-01 00:00:00'):865.17,时间戳('2013-05-01 00:00:00'):763.0,时间戳('2013-06-01 00:00:00'):802.99,时间戳('2013-07-01 00:00:00'):875.56,时间戳('2013-08-01 00:00:00'):754.4,时间戳('2013-09-01 00:00:00'):617.48,时间戳('2013-10-01 00:00:00'):994.75,时间戳('2013-11-01 00:00:00'):860.86,时间戳('2013-12-01 00:00:00'):786.66,时间戳('2014-01-01 00:00:00'):908.48,时间戳('2014-02-01 00:00:00'):980.88,时间戳('2014-03-01 00:00:00'):1453.73,时间戳('2014-04-01 00:00:00'):1473.33,时间戳('2014-05-01 00:00:00'):1480.44,时间戳('2014-06-01 00:00:00'):1433.91,时间戳('2014-07-01 00:00:00'):1386.58,时间戳('2014-08-01 00:00:00'):1437.35,时间戳('2014-09-01 00:00:00'):1207.07,时间戳('2014-10-01 00:00:00'):973.3,时间戳('2014-11-01 00:00:00'):962.18,时间戳('2014-12-01 00:00:00'):717.69,时间戳('2015-01-01 00:00:00'):873.06,时间戳('2015-02-01 00:00:00'):881.65,时间戳('2015-03-01 00:00:00'):1252.92,时间戳('2015-04-01 00:00:00'):866.94,时间戳('2015-05-01 00:00:00'):1498.05,时间戳('2015-06-01 00:00:00'):1282.31,时间戳('2015-07-01 00:00:00'):1411.33,时间戳('2015-08-01 00:00:00'):1379.05,时间戳('2015-09-01 00:00:00'):1334.52,时间戳('2015-10-01 00:00:00'):1231.86,时间戳('2015-11-01 00:00:00'):1088.14,时间戳('2015-12-01 00:00:00'):967.35,时间戳('2016-01-01 00:00:00'):1266.37,时间戳('2016-02-01 00:00:00'):1278.79,时间戳('2016-03-01 00:00:00'):1497.8,时间戳('2016-04-01 00:00:00'):1352.27},名称='成本')

第 2 步:我下载了

Step 1: My sample data

import pandas as pd
from pandas import Timestamp

s = pd.Series(
    {Timestamp('2013-03-01 00:00:00'): 838.2,
 Timestamp('2013-04-01 00:00:00'): 865.17,
 Timestamp('2013-05-01 00:00:00'): 763.0,
 Timestamp('2013-06-01 00:00:00'): 802.99,
 Timestamp('2013-07-01 00:00:00'): 875.56,
 Timestamp('2013-08-01 00:00:00'): 754.4,
 Timestamp('2013-09-01 00:00:00'): 617.48,
 Timestamp('2013-10-01 00:00:00'): 994.75,
 Timestamp('2013-11-01 00:00:00'): 860.86,
 Timestamp('2013-12-01 00:00:00'): 786.66,
 Timestamp('2014-01-01 00:00:00'): 908.48,
 Timestamp('2014-02-01 00:00:00'): 980.88,
 Timestamp('2014-03-01 00:00:00'): 1453.73,
 Timestamp('2014-04-01 00:00:00'): 1473.33,
 Timestamp('2014-05-01 00:00:00'): 1480.44,
 Timestamp('2014-06-01 00:00:00'): 1433.91,
 Timestamp('2014-07-01 00:00:00'): 1386.58,
 Timestamp('2014-08-01 00:00:00'): 1437.35,
 Timestamp('2014-09-01 00:00:00'): 1207.07,
 Timestamp('2014-10-01 00:00:00'): 973.3,
 Timestamp('2014-11-01 00:00:00'): 962.18,
 Timestamp('2014-12-01 00:00:00'): 717.69,
 Timestamp('2015-01-01 00:00:00'): 873.06,
 Timestamp('2015-02-01 00:00:00'): 881.65,
 Timestamp('2015-03-01 00:00:00'): 1252.92,
 Timestamp('2015-04-01 00:00:00'): 866.94,
 Timestamp('2015-05-01 00:00:00'): 1498.05,
 Timestamp('2015-06-01 00:00:00'): 1282.31,
 Timestamp('2015-07-01 00:00:00'): 1411.33,
 Timestamp('2015-08-01 00:00:00'): 1379.05,
 Timestamp('2015-09-01 00:00:00'): 1334.52,
 Timestamp('2015-10-01 00:00:00'): 1231.86,
 Timestamp('2015-11-01 00:00:00'): 1088.14,
 Timestamp('2015-12-01 00:00:00'): 967.35,
 Timestamp('2016-01-01 00:00:00'): 1266.37,
 Timestamp('2016-02-01 00:00:00'): 1278.79,
 Timestamp('2016-03-01 00:00:00'): 1497.8,
 Timestamp('2016-04-01 00:00:00'): 1352.27},
    name='Cost')

Step 2: I downloaded X-13ARIMA-SEATS Seasonal Adjustment Program to my downloads folder in Windows OS

Step 3: In Python's IDLE IDE, I changed my current path to where this program lives:

import os
os.chdir(r'C:\Users\owner\Downloads\x13asall_V1.1_B26\x13as')

Step 4: I import statsmodels and try to run x13_arima_analysis as follows:

import statsmodels.api as sm
sm.tsa.x13_arima_analysis(s)

Error received:

Traceback (most recent call last):
  File "<pyshell#104>", line 1, in <module>
    sm.tsa.x13_arima_analysis(s)
  File "C:\Python34\lib\site-packages\statsmodels-0.6.1-py3.4-win-amd64.egg\statsmodels\tsa\x13.py", line 417, in x13_arima_analysis
    spec_obj = pandas_to_series_spec(endog)
  File "C:\Python34\lib\site-packages\statsmodels-0.6.1-py3.4-win-amd64.egg\statsmodels\tsa\x13.py", line 310, in pandas_to_series_spec
    stperiod))
  File "C:\Python34\lib\site-packages\statsmodels-0.6.1-py3.4-win-amd64.egg\statsmodels\tsa\x13.py", line 271, in __init__
    title=title, name=series_name,
  File "C:\Python34\lib\site-packages\statsmodels-0.6.1-py3.4-win-amd64.egg\statsmodels\tsa\x13.py", line 218, in set_options
    for key, value in kwargs.iteritems():
AttributeError: 'dict' object has no attribute 'iteritems'

Note that I have the unofficial binaries of statsmodels installed (because it's impossible to install on my Windows machine) so I don't think I can alter the actual source but I do see the problem is here on this line.

Am I doing this wrong or is this a bug within statsmodels?

What version of statsmodels do I have? 0.6.1

>>> sm.__spec__
ModuleSpec(name='statsmodels.api', loader=<_frozen_importlib.SourceFileLoader object at 0x0000000007193470>, origin='C:\\Python34\\lib\\site-packages\\statsmodels-0.6.1-py3.4-win-amd64.egg\\statsmodels\\api.py')

解决方案

Not sure if I should close this question or keep it up for reference for anybody else that struggled with getting x13_arima_analysis working. In summary, I got it to work by changing a few lines... but in the end, I'd recommend going to Github first, and replace the x13.py file located in C:\Python34\Lib\site-packages\statsmodels-0.6.1-py3.4-win-amd64.egg\statsmodels‌​\tsa on your machine with the latest Github code to see if it fixes it for you. It fix it for me.

Working Example in action:

import pandas as pd
from pandas import Timestamp
import os
import matplotlib.pyplot as plt
import statsmodels.api as sm

PATH =r'C:\Users\owner\Downloads\x13asall_V1.1_B26\x13as'

os.chdir(PATH)

s = pd.Series(
    {Timestamp('2013-03-01 00:00:00'): 838.2,
 Timestamp('2013-04-01 00:00:00'): 865.17,
 Timestamp('2013-05-01 00:00:00'): 763.0,
 Timestamp('2013-06-01 00:00:00'): 802.99,
 Timestamp('2013-07-01 00:00:00'): 875.56,
 Timestamp('2013-08-01 00:00:00'): 754.4,
 Timestamp('2013-09-01 00:00:00'): 617.48,
 Timestamp('2013-10-01 00:00:00'): 994.75,
 Timestamp('2013-11-01 00:00:00'): 860.86,
 Timestamp('2013-12-01 00:00:00'): 786.66,
 Timestamp('2014-01-01 00:00:00'): 908.48,
 Timestamp('2014-02-01 00:00:00'): 980.88,
 Timestamp('2014-03-01 00:00:00'): 1453.73,
 Timestamp('2014-04-01 00:00:00'): 1473.33,
 Timestamp('2014-05-01 00:00:00'): 1480.44,
 Timestamp('2014-06-01 00:00:00'): 1433.91,
 Timestamp('2014-07-01 00:00:00'): 1386.58,
 Timestamp('2014-08-01 00:00:00'): 1437.35,
 Timestamp('2014-09-01 00:00:00'): 1207.07,
 Timestamp('2014-10-01 00:00:00'): 973.3,
 Timestamp('2014-11-01 00:00:00'): 962.18,
 Timestamp('2014-12-01 00:00:00'): 717.69,
 Timestamp('2015-01-01 00:00:00'): 873.06,
 Timestamp('2015-02-01 00:00:00'): 881.65,
 Timestamp('2015-03-01 00:00:00'): 1252.92,
 Timestamp('2015-04-01 00:00:00'): 866.94,
 Timestamp('2015-05-01 00:00:00'): 1498.05,
 Timestamp('2015-06-01 00:00:00'): 1282.31,
 Timestamp('2015-07-01 00:00:00'): 1411.33,
 Timestamp('2015-08-01 00:00:00'): 1379.05,
 Timestamp('2015-09-01 00:00:00'): 1334.52,
 Timestamp('2015-10-01 00:00:00'): 1231.86,
 Timestamp('2015-11-01 00:00:00'): 1088.14,
 Timestamp('2015-12-01 00:00:00'): 967.35,
 Timestamp('2016-01-01 00:00:00'): 1266.37,
 Timestamp('2016-02-01 00:00:00'): 1278.79,
 Timestamp('2016-03-01 00:00:00'): 1497.8,
 Timestamp('2016-04-01 00:00:00'): 1352.27},
    name='Cost')


res = sm.tsa.x13_arima_analysis(s)
res.plot()
plt.show()

这篇关于Python Statsmodels x13_arima_analysis:AttributeError:'dict'对象没有属性'iteritems'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆