首页 > 解决方案 > 将测试统计信息写入 google colab 中的文件

问题描述

我正在尝试生成 csv 文件的 ADF 测试统计信息。在这里,csv 存储在“表”中,并对其第二列值执行测试。我的目标是将统计结果写入文件。请提供必要的代码来做同样的事情。

#define function for ADF test
from statsmodels.tsa.stattools import adfuller
def adf_test(timeseries):
    #Perform Dickey-Fuller test:
    print ('Results of Dickey-Fuller Test:')
    dftest = adfuller(timeseries, autolag='AIC')
    dfoutput = pd.Series(dftest[0:4], index=['Test Statistic','p-value','#Lags Used','Number of Observations Used'])
    for key,value in dftest[4].items():
       dfoutput['Critical Value (%s)'%key] = value
    print (dfoutput)

#apply adf test on the series
adf_test(Table.iloc[:,1])

这是有关输出外观的示例。

Results of Dickey-Fuller Test:

Test Statistic                  -2.963707
p-value                          0.038426
#Lags Used                      13.000000
Number of Observations Used    243.000000
Critical Value (1%)             -3.457551
Critical Value (5%)             -2.873509
Critical Value (10%)            -2.573148
dtype: float64

在结果中,我希望将测试统计量和p 值写入文件。

标签: pythonfilestatisticsgoogle-colaboratory

解决方案


推荐阅读