# Partial autocorrelation in time series data

Like autocorrelation, the partial autocorrelation function (PACF) measures the correlation coefficient between a time-series and lagged versions of itself. However, it extends upon this idea by also removing the effect of previous time points. For example, a partial autocorrelation function of `order 3`

returns the correlation between our time series (`t_1`

, `t_2`

, `t_3`

, …) and its own values lagged by 3 time points (`t_4`

, `t_5`

, `t_6`

, …), but only after removing all effects attributable to lags 1 and 2.

The `plot_pacf()`

function in the `statsmodels`

library can be used to measure and plot the partial autocorrelation of a time series.

This is a part of the course

## “Visualizing Time Series Data in Python”

### Exercise instructions

- Import
`tsaplots`

from`statsmodels.graphics`

. - Use the
`plot_pacf()`

function from`tsaplots`

to plot the partial autocorrelation of the`'co2'`

column in`co2_levels`

. - Specify a maximum lag of 24.

### Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

```
# Import required libraries
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
____
# Display the partial autocorrelation plot of your time series
fig = ____(co2_levels[____], lags=____)
# Show plot
plt.show()
```

This exercise is part of the course

## Visualizing Time Series Data in Python

Visualize seasonality, trends and other patterns in your time series data.

You will go beyond summary statistics by learning about autocorrelation and partial autocorrelation plots. You will also learn how to automatically detect seasonality, trend and noise in your time series data.

Exercise 1: Autocorrelation and Partial autocorrelationExercise 2: Autocorrelation in time series dataExercise 3: Interpret autocorrelation plotsExercise 4: Partial autocorrelation in time series dataExercise 5: Interpret partial autocorrelation plotsExercise 6: Seasonality, trend and noise in time series dataExercise 7: Time series decompositionExercise 8: Plot individual componentsExercise 9: A quick reviewExercise 10: Visualize the airline datasetExercise 11: Analyze the airline datasetExercise 12: Time series decomposition of the airline dataset### What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.