# reshape-wide-to-long

## Description

<mark style="color:purple;">`reshape-wide-to-long`</mark> *adaptor transforms a datatable to a two-column datatable in which one column contains the column names of the original datatable and the second column is the respective value from each row.*

## Inputs

**`data`**\
Type: `datatable`\
Required: Yes\
The datatable in wide format.

**`static columns`**\
Type: `list`\
Required: No\
The list of columns which will not be reshaped. If unspecified, all columns will be reshaped

**`key column name`**\
Type: `text`\
Required: No\
The name of the column to which keys are added. If unspecified, defaults to `key`.

**`value column name`**\
Type: `text`\
Required: No\
The name of the column to which values are added. If unspecified, defaults to `value`.

## Outputs

**`data`**\
Type: `datatable`\
A datatable in long format.

## Examples

### Example 1: Default behaviour.

#### Inputs:

`data:`

| id | code | country        |
| -- | ---- | -------------- |
| 1  | GB   | United Kingdom |
| 2  | TR   | Turkey         |
| 3  | US   | United States  |

`static columns:` *null (empty)*

`key column name:` *null (empty)*

`value column name:` *null (empty)*

#### Outputs:

`data`:

| key     | value          |
| ------- | -------------- |
| id      | 1              |
| code    | GB             |
| country | United Kingdom |
| id      | 2              |
| code    | TR             |
| country | Turkey         |
| id      | 3              |
| code    | US             |
| country | United States  |

-> Transformed all the columns in the datatable, from wide to long, using the default `key` and `value` as the column names

### Example 2: Reshape with static columns.

#### Inputs:

`data:`

| id | code | country        |
| -- | ---- | -------------- |
| 1  | GB   | United Kingdom |
| 2  | TR   | Turkey         |
| 3  | US   | United States  |

`static columns:`

1. country

`key column name:` *null (empty)*

`value column name:` *null (empty)*

#### Outputs:

`data`:

| key  | value |
| ---- | ----- |
| id   | 1     |
| code | GB    |
| id   | 2     |
| code | TR    |
| id   | 3     |
| code | US    |

-> Transformed the columns `id` and `code` in the datatable, from wide to long, using the default `key` and `value` as the column names. The `country` column was not reshaped.&#x20;

### Example 3: Reshape with specific key column name and value column name.

#### Inputs:

`data:`

| id | code | country        |
| -- | ---- | -------------- |
| 1  | GB   | United Kingdom |
| 2  | TR   | Turkey         |
| 3  | US   | United States  |

`static columns:`

1. country

`key column name:` name

`value column name:` result

#### Outputs:

`data`:

| name | result |
| ---- | ------ |
| id   | 1      |
| code | GB     |
| id   | 2      |
| code | TR     |
| id   | 3      |
| code | US     |

-> Transformed the columns `id` and `code` in the datatable, from wide to long, using the `name` as key column name and `result` as the value column name.


---

# 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/reshape-wide-to-long.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.
