python实现-时间序列分析
import numpy as np
import pandas as pd
import datetime
import matplotlib.pyplot as plt
import statsmodels.api as sm
from dateutil.relativedelta import relativedelta
from statsmodels.tsa.seasonal import seasonal_decompose
#首先处理下数据
data=pd.read_excel("/Users/huangqiankun/Downloads/时时序数据.xlsx",index_col=0)
print(data.head(10))
data.index.name = None # 将index的name取消
data.reset_index(inplace=True)
data.drop(data.index[64], inplace=True)
start = datetime.datetime.strptime("2003-01", "%Y-%m") # 把一个时间字符串解析为时间元组
date_list = [start + relativedelta(months=x*3) for x in range(0, 64)] # 从2003-01-01开始逐月增加组成list
data['index'] = date_list
data.set_index(['index'], inplace=True)
print(data.head(10))
传统汽车销量 国内生产总值当季值(亿元)x1 ... 汽车整车股票指数 消费者信心指数
index ...
2003-01-01 102.1 29825.5 ... 1696.81 97.700000
2003-04-01 110.0 32537.3 ... 1912.54 87.666667
2003-07-01 112.1 35291.9 ... 1803.71 92.333333
2003-10-01 122.8 39767.4 ... 1922.48 94.666667
2004-01-01 131.1 34544.6 ... 1930.71 95.333333
2004-04-01 133.3 38700.8 ... 1245.70 92.566667
2004-07-01 121.0 41855.0 ... 1163.16 91.066667
2004-10-01 123.7 46739.8 ... 870.61 92.566667
2005-01-01 139.7 40453.3 ... 749.62 93.933333
2005-04-01 162.2 44793.1 ... 764.84 94.533333
来源:CSDN
作者:yxjwhhhh
链接:https://blog.csdn.net/yxjwhhhh/article/details/104732195