Replace values
Replace values — replaceValues
Substitute values in a column.
Use cases
- Standardize codes (
N→North,Y/N→Yes/No). - Clean stray characters with a regex pattern.
What it does
Replaces each exact match of to_replace in the column with value. Non-matching
values pass through unchanged.
Before
| order_id | region |
|---|---|
| 1001 | N |
| 1002 | S |
| 1003 | N |
| 1004 | E |
4 rows · 2 cols
Replace values (column=region, to_replace=N, value=North)
After
| order_id | region |
|---|---|
| 1001 | North |
| 1002 | S |
| 1003 | North |
| 1004 | E |
4 rows · 2 cols
Configuration
| Config key | Type | Required | Description |
|---|---|---|---|
column | string | Yes | Column to edit |
to_replace | any | Yes | Value (or regex pattern) to find |
value | any | Yes | Replacement value |
regex | bool | No | Treat to_replace as a regex (default false) |
Generated Python code
df_2 = df_1.assign(region=lambda _d: _d['region'].replace('N', 'North'))
Tips & common mistakes
- Literal vs regex: with
regex: falsethe whole value must match; withregex: true,to_replaceis a pattern andvalueis the substitution. - To map many values to new ones with an optional default, prefer Map values.