python时间序列平稳性_在ARIMA时间序列建模python pandas中提取Adfuller测试(平稳性测试)列表中的p值...

df

Col1 Col2 Col3

12 10 3

3 5 2

100 12 10

and so on.....

Code to write adfuller test for ARIMA modeling in Time series. (will calculate p value for all the columns of dataframe df)

import statsmodels.tsa.stattools as tsa

adf_results = {}

for col in df.columns.values:

adf_results[col] = tsa.adfuller(df[col])

Using this code I am getting outputs in below format: (output when I type adf_result)

[IN] adf_result

[OUT]

{'Col1': (-4.236149193618492,

0.0005719678593039654, #This is the second value for this column/p value

0,

37,

{'1%': -3.6209175221605827,

'5%': -2.9435394610388332,

'10%': -2.6104002410518627},

138.66116123406837),

'Col2': (-3.707023043984407,

0.004015446231411924, #This is the second value for this column/p value

0,

37,

{'1%': -3.6209175221605827,

'5%': -2.9435394610388332,

'10%': -2.6104002410518627},

144.6019873130419),

'Col3': (1.8083888603589304,

0.9983655107052215, #This is the second value for this column/p value

0,

37,

{'1%': -3.6209175221605827,

'5%': -2.9435394610388332,

'10%': -2.6104002410518627},

-74.4384052778039)}

and so on.

In this question, second value/p value is

0.0005719678593039654, 0.004015446231411924 and 0.9983655107052215 for the 3 columns taken.

I need columns where second value >0.05 in one list and columns where p value <0.05 in another list

So one list will be col1 and col2 (second value/p value<0.05) and the other list will be col3 (second value/p value<0.05)

解决方案import pandas as pd

from io import StringIO

data = StringIO("""

Col1 Col2 Col3

12 10 3

3 5 2

100 12 10

13 4 1

""")

# load data into data frame

df = pd.read_csv(data, sep=' ')

import statsmodels.tsa.stattools as tsa

adf_results = {}

for col in df.columns.values:

adf_results[col] = tsa.adfuller(df[col])

# loop over dictionary data

columns_big = []

columns_small = []

for key, value in adf_results.items():

if value[1] > 0.05:

columns_big.append(key)

else:

columns_small.append(key)

Output:

columns_big = ['Col1', 'Col3']

columns_small = ['Col2']

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值