Skip to main content

Replace Values

Replaces specified values in a data table with new values.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Table - The input data table in which to replace values.
  • Old Value - The value to be replaced.
  • New Value - The value to replace the old value with.

Options

  • Regex - Specifies whether to treat the Old Value as a regular expression. Options are:
    • True - Treat Old Value as a regular expression
    • False - Treat Old Value as a literal value
  • Output Type - Specifies whether to pass the table by reference or by value. Options are:
    • Pass By Reference
    • Pass By Value

Output

  • Table - The resulting data table with values replaced.

How It Works

The Replace Values node replaces specified values in a data table with new values. When executed, the node:

  1. Validates that the input table is not empty and is valid
  2. Checks if the table is a reference table and handles it appropriately
  3. Validates that both Old Value and New Value are provided
  4. Converts the data table to a pandas DataFrame
  5. Replaces all occurrences of the Old Value with the New Value
  6. Converts the modified DataFrame back to the data table format
  7. Returns the updated table

Requirements

  • A valid input data table
  • Valid Old Value and New Value inputs

Error Handling

The node will return specific errors in the following cases:

  • Empty or invalid input table
  • Empty Old Value
  • Empty New Value
  • Invalid table structure

Usage Notes

  • The Output Type option can be set to "Pass By Reference" for handling large tables more efficiently
  • When Regex is set to True, the Old Value is treated as a regular expression pattern
  • When Regex is set to False, the Old Value is treated as a literal value
  • The replacement operation affects all columns in the table
  • The node replaces all occurrences of the Old Value with the New Value

Usage Examples

Example 1: Replace a Literal Value

.then('a06926', 'Robomotion.Pandas.ReplaceValues', 'Expand City', {
inTable: Message('table'),
inOldValue: Custom('NYC'),
inNewValue: Custom('New York'),
outTable: Message('table')
})

Example 2: Normalise Blank Cells

Replace empty strings with a marker so downstream steps can spot them:

.then('b17c34', 'Robomotion.Pandas.ReplaceValues', 'Mark Missing', {
inTable: Message('table'),
inOldValue: Custom(''),
inNewValue: Custom('N/A'),
outTable: Message('table')
})

Example 3: Strip a Currency Symbol with a Regex

.then('c28d45', 'Robomotion.Pandas.ReplaceValues', 'Strip Currency', {
inTable: Message('table'),
inOldValue: Custom('^\\$'),
inNewValue: Custom(''),
optRegex: true,
outTable: Message('table')
})

Example 4: Clean Then Convert

Regex-clean a numeric column before changing its type, so the conversion does not fail:

- CSV To Data Table (invoices.csv) -> table
- Replace Values (table, "[^0-9.]", "", Regex: true) -> table
- Convert Type (table, "amount", float) -> table
- Sort Table (table, "amount", Descending) -> table

Tips

  • Regex is a real boolean (optRegex: true), unlike Order Type on Sort Table which is the string 'True'. The package mixes both conventions, so check each property rather than assuming
  • Replacement runs across every column; there is no column filter on this node. To limit the blast radius, split the column out with Get Column, replace, and merge back
  • With Regex enabled, remember to escape regex metacharacters in the old value - $, ., (, [
  • Replacing with an empty string leaves the cell empty rather than dropping the row
  • Values are matched as whole cell values unless Regex is enabled, so partial text needs a regex
  • Pass By Reference (optReference: 'True') avoids copying large tables between nodes