python - 将测试统计信息写入 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 值写入文件。
解决方案
推荐阅读
- python - 我想在新创建的类中创建多个海龟
- android - 链接可观察对象 RxJava
- python - 如何在python中逐行写入csv文件?
- r - 如何使用更改重复次数的 For、While、Repeat 函数
- eloquent - 数据透视表集合在同步后不更新
- ruby-on-rails - 如何在不再次调用 .save 的情况下将子记录的 id 保存在父项中?
- php - sabre:循环通过 TEL-property 不能提供预期的结果
- r - 无法使用文本数据创建 R 数据框来填充不同的列
- regex - Python 无法处理请求的 POST 响应
- java - 我该如何更改它以用 html 页面替换 404 页面错误?