Initializing playground…
← Back to roadmap

🎢 Rolling Windows — Interactive Playground

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.

1 · Basic rolling mean

Call series.rolling(window) to get a Rolling object, then call .mean(). The first positions are null (not enough data).

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

2 · minPeriods — allow partial windows

By default minPeriods = window. Set it lower to get results for the initial positions too.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

3 · Rolling sum, std, min, max

The Rolling object exposes several built-in aggregation methods.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

4 · Rolling count (handles nulls)

count() counts valid (non-null / non-NaN) observations in each window. It ignores minPeriods.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

5 · Rolling median

Useful for robust estimation — less sensitive to outliers than the mean.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

6 · Custom aggregation with apply()

Pass any function (values: readonly number[]) => number to apply().

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

7 · Centered window

Set center: true to centre the window label, giving a symmetric look-ahead/look-behind view.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

8 · DataFrame.rolling()

Aggregations are applied column-by-column, returning a new DataFrame with the same shape.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

API Reference

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