How to compute rolling window statistics

Given the sequential ordering of time series data, it is natural to compute familiar descriptive statistics for periods of a given length to detect stability or changes in behavior and obtain a smoothed representation that captures systematic aspects while filtering out the noise.

Rolling window statistics serve this process: they produce a new time series where each data point represents a summary statistic computed for a certain period of the original data. Moving averages are the most familiar example. The original data points can enter the computation with equal weights, or using weights to, for example, emphasize more recent data points. Exponential moving averages recursively compute weights that shrink or decay, for data points further away from the present. The new data points are typically a summary of all preceding data points, but they can also be computed from a surrounding window.

The pandas library includes very flexible functionality to define various window types, including rolling, exponentially weighted and expanding windows. In a second step, you can apply computations to each data captured by a window. These computations include built-in standard computations for individual series, such as the mean or the sum, the correlation or covariance for several series, as well as user-defined functions. The moving average and exponential smoothing examples in the following section make use of these tools.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset