replace_values
Replace specified values in a column with new ones.
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.
To change specific names in a column of texts from “pedro” to “pablo” and “maria” to “mariana”:
To change specific names in a column of texts from “pedro” to “pablo” and “maria” to “mariana”:
To change specific numbers in a column of numerical values from “20” to 99 and “30” to 100:
To replace null values in a column with a string:
To replace a specific numerical value in a column with null using the keyword null:
To replace a specific numerical value in a column with null using the string “null”:
General syntax for using the step in a recipe. Shows the inputs and outputs the step is expected to receive and will produce respectively. For futher details see sections below.
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"
).
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)
.
One or more additional parameters.