CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Manipulating Time Series Data in Python

Afficher le cours

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' to data and apply .interpolate() to fill missing values, and reassign to data.
  • Inspect the result using .info().
  • Create a .rolling() window using 360 periods, select the column 'Ozone', and assign the result to rolling.
  • Insert three new columns, 'q10', 'q50' and 'q90' into data, calculating the respective quantiles from rolling.
  • Plot data.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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


Modifier et exécuter le code