代码拉取完成,页面将自动刷新
import numpy as np
import pandas as pd
from pandas import Series
from matplotlib import pyplot
from statsmodels.tsa.seasonal import seasonal_decompose
dateparse = lambda dates: pd.datetime.strptime(dates, '%Y-%m')
data = pd.read_csv('international-airline-passengers.csv', parse_dates='Month', index_col='Month',date_parser=dateparse, infer_datetime_format=True)
# dat = Series.from_csv('data/international-airline-passengers.csv')
# print len(dat)
# date_range = pd.date_range(dat.index.min(),dat.index.max(),freq="Month")
print data
result = seasonal_decompose(data.values, model='additive',freq=12)
print result
trend = result.trend
seasonal = result.seasonal
resid = result.resid
print trend
print len(seasonal)
print resid
# arr = np.array(result.resid)
residDf = pd.DataFrame(np.array(resid))
residDf.to_csv('data/residair.csv', index=False, header=None)
trendDf = pd.DataFrame(np.array(trend))
trendDf.to_csv('data/trendair.csv', index=False, header=None)
seasonalDf = pd.DataFrame(np.array(seasonal))
seasonalDf.to_csv('data/seasonalair.csv', index=False, header=None)
# print arr
result.plot()
pyplot.show()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。