I'm trying to dealing with autocorrelation in python, and been using plot_acf and pacf from statsmodels. I want to plot figures looking like statsmodels' figures. So I have no choice but using this library.
Cut to the chase, there is no that significant correlation in my data so I'd like to omit zero lag which always has maximum correlation. It would be better to plot figures from lags=1 or 2. Is there any way to do this?
Under here, they are my codes I've been trying to find out the clear solution... Please help me!
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
register_matplotlib_converters
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
# PNA
# read data
df_pna = pd.read_csv('pna_data.txt', index_col=0, header=None, delim_whitespace=True, skiprows=[0,1,2,75,76,77,78,79])
df_pna.rename(columns = {1:'Jan', 2:'Feb', 3:'Mar', 4:'Apr', 5:'May', 6:'Jun', 7:'Jul', 8:'Aug', 9:'Sep', 10:'Oct', 11:'Nov', 12:'Dec'}, inplace = True)
# autocorrelation
empty_pna = []
for k in range(len(df_pna.columns)):
empty_pna.append(df_pna.iloc[:,k].to_list())
months_pna = []
for i in empty_pna:
for j in i:
months_pna.append(j)
# plot
# satsmodels
plt.close()
fig = plt.figure(figsize=(7,8))
ax1 = fig.add_subplot(2, 1, 1)
ax2 = fig.add_subplot(2, 1, 2)
plot_acf(months_pna, lags=20, ax=ax1)
ax1.set_title('PNA AC with lags 20', fontsize=10)
plot_pacf(months_pna, lags=20, method='ywm', ax=ax2)
ax2.set_title('PNA PAC with lags 20', fontsize=10)
plt.show()
plt.close()
Pass
zero=False
to omit lag zero: