> ## Documentation Index
> Fetch the complete documentation index at: https://docs.graphext.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 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.

<Accordion title="Examples" icon="code" defaultOpen="true">
  <Tabs>
    <Tab title="Example 1">
      To change specific names in a column of texts from "pedro" to "pablo" and "maria" to "mariana":

      ```stan theme={null}
      replace_values(ds.names, {
        "pedro": "pablo",
        "maria": "mariana"
      }) -> (ds.replaced)
      ```
    </Tab>

    <Tab title="Example 2">
      To change specific numbers in a column of numerical values from "20" to 99 and "30" to 100:

      ```stan theme={null}
      replace_values(ds.age, {
        "20": 99,
        "30": 100
      }) -> (ds.replaced)
      ```
    </Tab>

    <Tab title="Example 3">
      To replace null values in a column with a string:

      ```stan theme={null}
      replace_values(ds.column, {
        "": "something not null"
      }) -> (ds.replaced)
      ```
    </Tab>

    <Tab title="Example 4">
      To replace a specific numerical value in a column with null using the keyword null:

      ```stan theme={null}
      replace_values(ds.age, {
        "30": null
      }) -> (ds.replaced)
      ```
    </Tab>

    <Tab title="Example 5">
      To replace a specific numerical value in a column with null using the string "null":

      ```stan theme={null}
      replace_values(ds.age, {
        "30": "null"
      }) -> (ds.replaced)
      ```
    </Tab>

    <Tab title="Signature">
      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.

      ```stan theme={null}
      replace_values(original: category|text|number|date|list, {
          "param": value,
          ...
      }) -> (replaced: column)
      ```
    </Tab>
  </Tabs>
</Accordion>

## 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"`).

<Accordion title="Inputs" icon="right-to-bracket">
  <ParamField path="original" type="column[category|text|number|date|list]" required>
    A column containing text-like values.
  </ParamField>
</Accordion>

<Accordion title="Outputs" icon="right-from-bracket">
  <ParamField path="replaced" type="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.
  </ParamField>
</Accordion>

## 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)`.

<Accordion title="Parameters" defaultOpen="true" icon="sliders">
  <ParamField path="Items" type="[string, number, null]">
    One or more additional parameters.
  </ParamField>
</Accordion>
