Ciaren

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, else F).
  • 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).

Before
nameagecountry
Alice25US
Bob16US
Carol30UK
3 rows · 3 cols
Conditional column: age ≥ 18 AND country = US → us_adult; else → other
After
nameagecountrysegmentnew
Alice25USus_adult
Bob16USother
Carol30UKother
3 rows · 4 cols

Configuration

Config keyTypeRequiredDescription
new_columnstringYesName of the column to add
rulesobject[]YesOrdered rules: { match, conditions, result }
defaultanyNoValue 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/notnull take no value.
  • For a simple value lookup (no comparisons) use Map values; to merely keep matching rows use Filter rows.

See also