'How do I deal with non-stationery data for time series analysis (autocorrelation function (ACF) and partial autocorrelation function (PACF)

I am trying to plot the autocorrelation function (ACF) and partial autocorrelation function (PACF) for 30 lags of 'Nile'

import statsmodels.api as sm
import matplotlib.pyplot as plt

nile = sm.datasets.get_rdataset("Nile").data

from statsmodels.tsa.stattools import adfuller

def check_stationarity(series):
# Copied from https://machinelearningmastery.com/time-series-data-stationary-python/

    result = adfuller(series.values)

    print('ADF Statistic: %f' % result[0])
    print('p-value: %f' % result[1])
    print('Critical Values:')
    for key, value in result[4].items():
        print('\t%s: %.3f' % (key, value))

    if (result[1] <= 0.05) & (result[4]['5%'] > result[0]):
        print("\u001b[32mStationary\u001b[0m")
    else:
        print("\x1b[31mNon-stationary\x1b[0m")
    
    check_stationarity(nile['time'])

ADF Statistic: 0.257617 p-value: 0.975314 Critical Values: 1%: -3.505 5%: -2.894 10%: -2.584

Non-stationary

Given that it is non-stationary, what should I do and to plot the autocorrelation function (ACF) and partial autocorrelation function (PACF) for 30 lags



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source