Session Ready
Exercise

Rolling mean and frequency

In this exercise, some hourly weather data is pre-loaded for you. You will continue to practice resampling, this time using rolling means.

Rolling means (or moving averages) are generally used to smooth out short-term fluctuations in time series data and highlight long-term trends. You can read more about them here.

To use the .rolling() method, you must always use method chaining, first calling .rolling() and then chaining an aggregation method after it. For example, with a Series hourly_data, hourly_data.rolling(window=24).mean() would compute new values for each hourly point, based on a 24-hour window stretching out behind each point. The frequency of the output data is the same: it is still hourly. Such an operation is useful for smoothing time series data.

Your job is to resample the data using the combination of .rolling() and .mean(). You will work with the same DataFrame df from the previous exercise.

Instructions
100 XP
  • Use partial string indexing to extract temperature data from August 1 2010 to August 15 2010. Assign to unsmoothed.
  • Use .rolling() with a 24 hour window to smooth the mean temperature data. Assign the result to smoothed.
  • Use a dictionary to create a new DataFrame august with the time series smoothed and unsmoothed as columns.
  • Plot both the columns of august as line plots using the .plot() method.