import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from statsmodels.graphics.tsaplots import plot_acf
from statsmodels.tsa.stattools import adfuller as ADF
from statsmodels.graphics.tsaplots import plot_pacf
from statsmodels.stats.diagnostic import acorr_ljungbox
%matplotlib inline
%pylab inline
#jupyter中文显示是方框,加入下面两行即可显示中文,若嫌麻烦,也可去网上搜索如何永久显示中文
plt.rcParams['font.sans-serif'] = ['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号
pylab.rcParams['figure.figsize'] = (10, 6) #设置输出图片大小
sns.set(color_codes=True) #seaborn设置背景
np.random.seed(20211120)
x = np.random.normal(10, 5, 50)
t = np.linspace(1,20,50)
y = x + t
df = {'x':list(x)}
data = pd.DataFrame(df)
dt1 = pd.date_range(start="1900", end="1950", freq="Y")
data.index = dt1
%config InlineBackend.figure_format = 'retina'
data.plot()
plot_acf(data).show()
print(u'原始序列的ADF检验结果为:', ADF(data[u'x']))
plot_pacf(data).show()
原始序列的ADF检验结果为: (-5.65584060487371, 9.62567971845179e-07, 0, 49, {‘1%’: -3.5714715250448363, ‘5%’: -2.922629480573571, ‘10%’: -2.5993358475635153}, 236.10635693304116)