Initializing playground…
← Back to roadmap

📈 cumulative operations — Interactive Playground

Compute running totals, products, maxima, and minima. Mirrors pandas.Series.cumsum() / cumprod() / cummax() / cummin().
Edit any code block below and press ▶ Run (or Ctrl+Enter) to execute it live in your browser.

1 · cumsum: running total

cumsum(series) returns a new Series where each value is the sum of all preceding values plus the current one. Mirrors pandas.Series.cumsum().

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

2 · cumprod: running product

cumprod(series) returns a new Series where each value is the product of all values up to and including that position. Mirrors pandas.Series.cumprod().

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

3 · cummax and cummin

cummax(series) tracks the running maximum; cummin(series) tracks the running minimum. Both work on numbers, strings, and booleans.

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

4 · Handling missing values (skipna)

By default skipna: true: missing values return NaN/null in the result but do not affect the running accumulator. With skipna: false, any missing value poisons all subsequent results.

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

5 · DataFrame: axis=0 (column-wise)

dataFrameCumsum(df) applies the operation independently to each column (axis=0 is the default, same as pandas).

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

6 · DataFrame: axis=1 (row-wise)

With axis: 1 (or axis: "columns"), the operation is applied across columns for each row — each cell becomes the cumulative value of all columns to its left plus itself.

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

7 · Real-world example: portfolio tracking

Track the running portfolio value and the running drawdown (how far we are from the all-time high) using cumsum and cummax.

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

8 · String series: lexicographic cummax / cummin

cummax and cummin work on any comparable type, including strings (lexicographic ordering).

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

API Reference

All cumulative functions accept a Series (or DataFrame variant) and return a new Series/DataFrame of the same shape. The skipna option controls missing-value handling; axis controls direction for DataFrames.

// Series cumulative operations
cumsum(series, { skipna?: boolean }): Series
cumprod(series, { skipna?: boolean }): Series
cummax(series, { skipna?: boolean }): Series
cummin(series, { skipna?: boolean }): Series

// DataFrame cumulative operations
dataFrameCumsum(df, { axis?: 0 | 1, skipna?: boolean }): DataFrame
dataFrameCumprod(df, { axis?: 0 | 1, skipna?: boolean }): DataFrame
dataFrameCummax(df, { axis?: 0 | 1, skipna?: boolean }): DataFrame
dataFrameCummin(df, { axis?: 0 | 1, skipna?: boolean }): DataFrame