select-columns
Description
select-columns
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.
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
:YearMonthSales (USD)Sales (GBP)Sales (EUR)2020
Jan
1458
1156
1345
2020
Feb
9874
7835
9110
2020
Mar
4562
3601
4173
2020
Apr
3654
2885
3342
column names
:Month
Sales (GBP)
Outputs:
data
:MonthSales (GBP)Jan
1156
Feb
7835
Mar
3601
Apr
2885
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
:YearMonthSales (USD)Sales (GBP)Sales (EUR)2020
Jan
1458
1156
1345
2020
Feb
9874
7835
9110
2020
Mar
4562
3601
4173
2020
Apr
3654
2885
3342
column names
:Month
pattern
:/Sales .*/
Outputs:
data
:MonthSales (USD)Sales (GBP)Sales (EUR)Jan
1458
1156
1345
Feb
9874
7835
9110
Mar
4562
3601
4173
Apr
3654
2885
3342
Use Cases
Remove duplicate columns after joining multiple datatables.
Reorder columns before exporting.
Last updated