pandas.Series.rolling

Provide rolling window calculations.

New in version 0.18.0.

param window
int, or offset

Size of the moving window. This is the number of observations used for calculating the statistic. Each window will be a fixed size.

If its an offset then this will be the time period of each window. Each window will be a variable sized based on the observations included in the time-period. This is only valid for datetimelike indexes. This is new in 0.19.0

param min_periods
int, default None

Minimum number of observations in window required to have a value (otherwise result is NA). For a window that is specified by an offset, min_periods will default to 1. Otherwise, min_periods will default to the size of the window.

param center
bool, default False

Set the labels at the center of the window.

param win_type
str, default None

Provide a window type. If None, all points are evenly weighted. See the notes below for further information.

param on
str, optional

For a DataFrame, a datetime-like column on which to calculate the rolling window, rather than the DataFrame’s index. Provided integer column is ignored and excluded from result since an integer index is not used to calculate the rolling window.

param axis

int or str, default 0

param closed
str, default None

Make the interval closed on the ‘right’, ‘left’, ‘both’ or ‘neither’ endpoints. For offset-based windows, it defaults to ‘right’. For fixed windows, defaults to ‘both’. Remaining cases not implemented for fixed windows.

New in version 0.20.0.

return

a Window or Rolling sub-classed for the particular operation

Limitations

Parameters center, win_type, on, axis and closed are supported only with default values.

Examples

Calculate the rolling minimum.
import pandas as pd
from numba import njit


@njit
def series_rolling_min():
    series = pd.Series([4, 3, 5, 2, 6])  # Series of 4, 3, 5, 2, 6
    out_series = series.rolling(3).min()

    return out_series  # Expect series of NaN, NaN, 3.0, 2.0, 2.0


print(series_rolling_min())
$ python ./series/rolling/series_rolling_min.py
0    NaN
1    NaN
2    3.0
3    2.0
4    2.0
dtype: float64

Todo

Add support of parameters center, win_type, on, axis and closed

See also

expanding

Provides expanding transformations.

ewm

Provides exponential weighted functions.