# replace-values-in-columns

<mark style="color:purple;">`replace-values-in-columns`</mark> *adaptor replaces all instances of a pattern in one or more columns in a datatable.*

The replacement values can be written to the original columns or new columns.

## Inputs

**`data`**\
Type: `datatable`\
Required: Yes\
The datatable containing values to be replaced.

**`columns`**\
Type: `dictionary`\
Required: Yes\
A dictionary of existing column names with names of new columns, where the dictionary keys are the names of existing columns, and the dictionary values are the names of the columns to which the replacement values are written. If a dictionary value is left blank, the replacement values are written to the original column.

**`pattern`**\
Type: `text`\
Required: Yes\
The text or regular expression to be replaced. The pattern is treated as a regular expression if it begins and ends with `/` (e.g., `/.*/`).

**`replacement`**\
Type: `text`\
Required: No\
The text that replaces all instances of the `pattern`. If unspecified, matches will be replaced with blank text. If a regular expression was used as a pattern, capture groups can be included as `$1`, `$2`, etc.

## Outputs

**`data`**\
Type: `datatable`\
A datatable with replacement values written to the original columns or new columns.

## Examples

### Example 1: Default behaviour.

Inputs:

`data`:

| id | code | name           |
| -- | ---- | -------------- |
| 1  | GB   | United Kingdom |
| 2  | TR   | Turkey         |
| 3  | US   | United States  |
| 4  | IND  | India          |

`columns`:

| KEY  | VALUE |
| ---- | ----- |
| code |       |

`pattern`: GB

`replacement`: UK

#### Outputs:

`list`:

| id | code | name           |
| -- | ---- | -------------- |
| 1  | UK   | United Kingdom |
| 2  | TR   | Turkey         |
| 3  | US   | United States  |
| 4  | IND  | India          |

-> Replaced the value `GB` in the existing `code` column with the value `UK`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cgps.gitbook.io/data-flo/reference-guide/replace-values-in-columns.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
