code
import pandas as pd
from statsmodels.tsa.arima_model import ARIMA
from datetime import datetime,timedelta,date,time
import warnings
warnings.filterwarnings('ignore')
df = pd.read_excel('01.xlsx',header=0,parse_dates=True,index_col=0,squeeze=True)
d = pd.date_range(df.index.min(),df.index.max())
res = pd.Series(df['Close'],d)
res = res.dropna()
print('-----original data-----')
print(res)
#arima
r = ARIMA(res,(2,1,0))
model_fit = r.fit(disp=0)
afew = 130
pred = model_fit.predict(start = df.index.max()+timedelta(1), end = df.index.max()+timedelta(afew),typ='levels',dynamic =True)
print('-----'+ str(afew) +' day forecast predict data-----')
print(pred)
沒報錯:
2017-05-03 to 2017-05-27
預測五月資料
有報錯:
· 2017-05-03 to 2017-06-10
· 2017-05-03 to 2017-07-12
· 2017-05-03 to 2017-08-30
只要我想預測跨月分資料,就報錯
請問該如何解決呢?謝謝!
按照錯誤訊息,應該是2017-08-30哪一筆資料有問題,可以用下列指令查詢:
df.loc['2017-08-30']
或
df.loc['2017-08-30 00:00:00']