> For the complete documentation index, see [llms.txt](https://cgps.gitbook.io/data-flo/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cgps.gitbook.io/data-flo/reference-guide/select-columns.md).

# select-columns

## Description

<mark style="color:purple;">`select-columns`</mark> *adaptor selects a list of columns from a datatable in a specified order.*

Columns can be selected based on a list of columns, text string matching, or a regular expression. These methods can be combined, so a list of columns can be supplied in addition to a regular expression to select additional columns.&#x20;

## Inputs

**`data`**\
Type: `datatable`\
Required: Yes\
The datatable containing columns to be selected.

**`column names`**\
Type: `list`\
Required: No\
The list of columns to be included in the specified order.

**`pattern`**\
Type: `text`\
Required: No\
Specifies the pattern (a text or a regular expression) to select columns whose name matches that pattern. Matching columns will be added after any columns specified in `column names`, and in the order in which they appear in the original datatable. The pattern is treated as a regular expression if it begins and ends with `/` (e.g. /.\*/).

## Outputs

**`data`**\
Type: `datatable`\
A datatable with the selected columns.

## Examples

### Example 1: Default behaviour.

Inputs:

* `data`:

  <table><thead><tr><th width="98.33391915641477">Year</th><th width="88">Month</th><th width="129">Sales (USD)</th><th width="122">Sales (GBP)</th><th width="127">Sales (EUR)</th></tr></thead><tbody><tr><td>2020</td><td>Jan</td><td>1458</td><td>1156</td><td>1345</td></tr><tr><td>2020</td><td>Feb</td><td>9874</td><td>7835</td><td>9110</td></tr><tr><td>2020</td><td>Mar</td><td>4562</td><td>3601</td><td>4173</td></tr><tr><td>2020</td><td>Apr</td><td>3654</td><td>2885</td><td>3342</td></tr></tbody></table>
* `column names`:
  1. `Month`
  2. `Sales (GBP)`

#### Outputs:

* `data`:

  <table><thead><tr><th width="109.3274336283186">Month</th><th width="146">Sales (GBP)</th></tr></thead><tbody><tr><td>Jan</td><td>1156</td></tr><tr><td>Feb</td><td>7835</td></tr><tr><td>Mar</td><td>3601</td></tr><tr><td>Apr</td><td>2885</td></tr></tbody></table>

### Example 2: Selecting columns using a regular expression.

In this example, we use the regular expression `/^Sales .*/` as a value for the `pattern` input to select columns which start with `Sales`.

Inputs:

* `data`:

  <table><thead><tr><th width="98.04973357015986">Year</th><th width="88">Month</th><th width="129">Sales (USD)</th><th width="122">Sales (GBP)</th><th width="127">Sales (EUR)</th></tr></thead><tbody><tr><td>2020</td><td>Jan</td><td>1458</td><td>1156</td><td>1345</td></tr><tr><td>2020</td><td>Feb</td><td>9874</td><td>7835</td><td>9110</td></tr><tr><td>2020</td><td>Mar</td><td>4562</td><td>3601</td><td>4173</td></tr><tr><td>2020</td><td>Apr</td><td>3654</td><td>2885</td><td>3342</td></tr></tbody></table>
* `column names`:
  1. `Month`
* `pattern`:\
  `/Sales .*/`

#### Outputs:

* `data`:

  <table><thead><tr><th width="116.05882352941177">Month</th><th width="129">Sales (USD)</th><th width="122">Sales (GBP)</th><th width="127">Sales (EUR)</th></tr></thead><tbody><tr><td>Jan</td><td>1458</td><td>1156</td><td>1345</td></tr><tr><td>Feb</td><td>9874</td><td>7835</td><td>9110</td></tr><tr><td>Mar</td><td>4562</td><td>3601</td><td>4173</td></tr><tr><td>Apr</td><td>3654</td><td>2885</td><td>3342</td></tr></tbody></table>

## Use Cases

* Remove duplicate columns after joining multiple datatables.
* Reorder columns before exporting.
