Sliding-window aggregations — mirrors
pandas.Series.rolling() and
pandas.DataFrame.rolling().
Edit any code block below and press ▶ Run
(or Ctrl+Enter) to execute it live in your browser.
Call series.rolling(window) to get a Rolling object,
then call .mean(). The first positions are null (not enough data).
By default minPeriods = window. Set it lower to get results for
the initial positions too.
The Rolling object exposes several built-in aggregation methods.
count() counts valid (non-null / non-NaN) observations in each
window. It ignores minPeriods.
Useful for robust estimation — less sensitive to outliers than the mean.
Pass any function (values: readonly number[]) => number to
apply().
Set center: true to centre the window label, giving a symmetric
look-ahead/look-behind view.
Aggregations are applied column-by-column, returning a new DataFrame with the same shape.
The Rolling object provides sliding-window aggregations. Use
series.rolling(window, opts?) or
df.rolling(window, opts?) to create one, then chain an aggregation
method.
series.rolling(window: number, {
minPeriods?: number, // default = window
center?: boolean, // default false — trailing window
}): Rolling
// Aggregation methods
rolling.mean(): Series
rolling.sum(): Series
rolling.std(): Series
rolling.var(): Series
rolling.min(): Series
rolling.max(): Series
rolling.count(): Series
rolling.median(): Series
rolling.apply(fn): Series
// DataFrame — aggregations applied column-by-column
df.rolling(window, opts?).mean(): DataFrame