首页 > 解决方案 > 为什么我收到 ValueError: too many values to unpack (expected 2)?

问题描述

我的 df 'td' 是一个时间序列数据,索引月份和一列的性能值介于 0-1 之间。我正在尝试进行平稳性测试

'''

def stationarity_test(timeseries):
    """"Augmented Dickey-Fuller Test
    Test for Stationarity"""
    from statsmodels.tsa.stattools import adfuller
    print("Results of Dickey-Fuller Test:")
    df_test = adfuller(timeseries, autolag = "AIC")
    df_output = pd.Series(df_test[0:4],
                          index = ["Test Statistic", "p-value", "#Lags Used",
                                   "Number of Observations Used"])
    print(df_output)
stationarity_test(td)

'''

收到的错误:Dickey-Fuller 测试的结果:

Traceback (most recent call last):

  File "<ipython-input-143-69a68080d36a>", line 12, in <module>
    stationarity_test(td)

  File "<ipython-input-143-69a68080d36a>", line 6, in stationarity_test
    df_test = adfuller(timeseries, autolag = "AIC")

  File "C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py", line 221, in adfuller
    xdall = lagmat(xdiff[:, None], maxlag, trim='both', original='in')

  File "C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\tsa\tsatools.py", line 397, in lagmat
    nobs, nvar = xa.shape

ValueError: too many values to unpack (expected 2)

标签: python-3.x

解决方案


推荐阅读