Conditional column
Conditional column — conditionalColumn
Build a column from ordered if/elif/else rules (CASE-WHEN). The first matching rule wins; rows matching none take the default. Each rule can combine several conditions with match ALL (AND) or match ANY (OR).
Use cases
- Grade buckets (
score >= 90 → A,>= 70 → B, elseF). - Segment customers on multiple criteria (
age >= 18 AND country == US → us_adult). - Flag rows that satisfy any of several conditions.
What it does
Rules are evaluated top to bottom; the first match assigns the result. Rows
matching no rule receive the default value (or null if none is set).
| name | age | country |
|---|---|---|
| Alice | 25 | US |
| Bob | 16 | US |
| Carol | 30 | UK |
| name | age | country | segmentnew |
|---|---|---|---|
| Alice | 25 | US | us_adult |
| Bob | 16 | US | other |
| Carol | 30 | UK | other |
Configuration
| Config key | Type | Required | Description |
|---|---|---|---|
new_column | string | Yes | Name of the column to add |
rules | object[] | Yes | Ordered rules: { match, conditions, result } |
default | any | No | Value when no rule matches |
Each rule's conditions is a list of { column, operator, value }, and match
is all (AND, the default) or any (OR). A single-condition rule may also be
written flat as { column, operator, value, result }.
Condition operators: == (or eq), != (or ne), > (or gt), >=
(or gte), < (or lt), <= (or lte), contains, startswith,
endswith, isnull, notnull.
Generated Python code
# rule: age >= 18 AND country == "US" → "us_adult"; default "other"
df_2 = df_1.assign(segment=lambda _d: np.select([(_d['age'] >= 18) & (_d['country'] == 'US')], ['us_adult'], default='other'))
Tips & common mistakes
- Order matters — rules are evaluated top to bottom and the first match wins, so put the most specific rules first.
- Numeric vs text values: compare a numeric column with a number
(
amount >= 5000) and a text column with a string — the editor accepts both. isnull/notnulltake no value.- For a simple value lookup (no comparisons) use Map values; to merely keep matching rows use Filter rows.