Skip to main content
This function enables the replacement of specified values in a column with new ones. It takes a mapping object, where each key-value pair represents an “old value” -> “new value” transformation. The function scans the column for values that match any of the keys in the mapping object and replaces them with their corresponding new values. This function is case-sensitive and performs exact matches. For numeric replacements, it’s important to note that keys in the mapping object need to be strings, even for numeric columns. The function will internally convert these keys into numbers for comparison.

Usage

The following examples show how the step can be used in a recipe.

Examples

  • Example 1
  • Example 2
  • Example 3
  • Example 4
  • Example 5
  • Signature
To change specific names in a column of texts from “pedro” to “pablo” and “maria” to “mariana”:
replace_values(ds.names, {
  "pedro": "pablo",
  "maria": "mariana"
}) -> (ds.replaced)

Inputs & Outputs

The following are the inputs expected by the step and the outputs it produces. These are generally columns (ds.first_name), datasets (ds or ds[["first_name", "last_name"]]) or models (referenced by name e.g. "churn-clf").
original
column[category|text|number|list]
required
A column containing text-like values.
replaced
column
required
The output column’s data type will depend on the input and specified parameters:
  • text: if input is text and parameter "as_category": false
  • category: if input is not a column of lists and "as_category": true
  • list: if input is a column of lists, list of the same kind as the input.

Configuration

The following parameters can be used to configure the behaviour of the step by including them in a json object as the last “input” to the step, i.e. step(..., {"param": "value", ...}) -> (output).

Parameters

Items
[string, number, null]
One or more additional parameters.
I