Shape · Columns

Replace Values

Swaps text in a column for other text, such as 'N/A' to blank or 'NY' to 'New York'. Each rule replaces its text wherever it appears in a value, as plain text or a pattern.

Also known as: Find and replace, recode

How it works

Pick the Column, then click Add replacement for each pair of find value and replace with. A plain find replaces that text wherever it occurs inside a value, not only whole values, so NY also changes NYC; tick regex to make the find an RE2 pattern that replaces every match and may use \1 for a capture group. Rules run in order, each on the result of the one before, and a rule with an empty find is skipped. The column is treated as text, so a number column comes out as text. The Output column box leaves the column in place when blank or appends a new column.

Inputs and outputs

Inputs

  • data — Table

Outputs

  • data — Table

Settings

The Attributes panel of Replace Values, as in the app: the controls work, but nothing runs — there is no data behind it.

The same settings, as the Assistant writes them
{
  column: string
  replacements: [{ from: string, to: string, regex: boolean }]
  outputColumn?: string
}

regex false = replace the literal text; regex true = from is an RE2 regex replacing every match (DuckDB regexp_replace) and to may use \1 for a group, e.g. from "[^0-9]" to "" keeps only digits

Example

A status column mixes N/A, n/a and real values, and a phone column has punctuation. On status add N/A to blank and n/a to blank. On phone add one rule with regex ticked, find [^0-9], replace with nothing, and write to phone_digits.

phonephone_digits
+44 (0)20 7946-09584402079460958
NULLNULL