Rolling quantiles for daily air quality in nyc
You learned in the last video how to calculate rolling quantiles to describe changes in the dispersion of a time series over time in a way that is less sensitive to outliers than using the mean and standard deviation.
Let's calculate rolling quantiles - at 10%, 50% (median) and 90% - of the distribution of daily average ozone concentration in NYC using a 360-day rolling window.
This exercise is part of the course
Manipulating Time Series Data in Python
Exercise instructions
We have already imported pandas as pd and matplotlib.pyplot as plt. We have also loaded the ozone data from 2000-2017 into the variable data.
- Apply
.resample()with daily frequency'D'todataand apply.interpolate()to fill missing values, and reassign todata. - Inspect the result using
.info(). - Create a
.rolling()window using 360 periods, select the column'Ozone', and assign the result torolling. - Insert three new columns,
'q10','q50'and'q90'intodata, calculating the respective quantiles fromrolling. - Plot
data.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Resample, interpolate and inspect ozone data here
data = ____
# Create the rolling window
rolling = ____
# Insert the rolling quantiles to the monthly returns
data['q10'] = ____
data['q50'] = ____
data['q90'] = ____
# Plot the data