Initializing playground…
← Back to roadmap

where / mask

Conditional value selection and replacement — mirrors pandas.Series.where and pandas.DataFrame.mask.

1 — whereSeries: keep values where condition is true

whereSeries(series, cond) keeps each element where cond is true and replaces it with null (or a custom other) where cond is false.

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

2 — maskSeries: replace values where condition is true

maskSeries is the inverse of whereSeries: it replaces where cond is true and keeps where cond is false.

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

3 — Boolean Series as condition

Pass a Series<boolean> (or a plain boolean array) as the condition for position-aligned filtering.

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

4 — whereDataFrame: cell-wise filtering on a DataFrame

whereDataFrame(df, cond) applies the condition independently to each cell across all columns.

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

5 — maskDataFrame: replace cells matching condition

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

6 — DataFrame condition (boolean DataFrame)

Pass a boolean DataFrame as the condition for per-cell control.

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

7 — Combining where and mask for range clamping

Chaining whereSeries and maskSeries is a clean way to apply lower and upper bounds.

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

8 — where / mask vs. clip

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