Table.select_columns
select_columnscolumns reordercase_sensitivityerror_on_missing_columnson_problems
Group: Selections
Aliases: select fields
Documentation
Creates a new table with a chosen subset of columns, as specified by the columns
, from the input table. Any unmatched input columns will be dropped from the output.
Arguments
columns
: Specifies columns by a single instance or Vector of names; indexes or regular expressions to match names; or aBy_Type
selector to choose columns by type.case_sensitivity
: Controls whether to be case sensitive when matching column names.reorder
: By default, or if set toFalse
, columns in the output will be in the same order as in the input table. IfTrue
, the order in the output table will match the order in the columns list. If a column is matched by multiple selectors in reorder mode, it will be placed at the position of the first one matched.error_on_missing_columns
: Specifies if a missing input column should result in an error regardless of theon_problems
settings. Defaults toTrue
.on_problems
: Specifies how to handle problems if they occur, reporting them as warnings by default.
Returns
- A new table with the chosen subset of columns.
Examples
Select columns by name.
table = Table.from_rows ["bar","foo","buzz","bizz"] [["John", "25","abc","123"]]
output = table.select_columns ["bar", "foo"]
Returns a Table
bar | foo |
---|---|
John | 25 |
Select columns by name, reordering the result.
table = Table.from_rows ["bar","foo","buzz","bizz"] [["John", "25","abc","123"]]
output = table.select_columns ["foo", "bar"] reorder=True
Returns a Table
foo | bar |
---|---|
25 | John |
Select columns matching a regular expression.
table = Table.from_rows ["bar","foo","buzz","bizz"] [["John", "25","abc","123"]]
output = table.select_columns [regex "b.+"]
Returns a Table
bar | buzz | bizz |
---|---|---|
John | abc | 123 |
Select the first two columns and the last column, moving the last one to front.
table = Table.from_rows ["bar","foo","buzz","bizz"] [["John", 25,"abc",123]]
output = table.select_columns [-1, 0, 1] reorder=True
Returns a Table
bizz | bar | foo |
---|---|---|
123 | John | 25 |
Select integer columns.
table = Table.from_rows ["bar","foo","buzz","bizz"] [["John", 25,"abc",123]]
output = table.select_columns [..By_Type ..Integer]
Returns a Table
foo | bizz |
---|---|
25 | 123 |
Errors
- If there are no columns in the output table, a
No_Output_Columns
is raised as an error regardless of the problem behavior, because it is not possible to create a table without any columns. - If a column in
columns
is not in the input table, aMissing_Input_Columns
is raised as an error, unlesserror_on_missing_columns
is set toFalse
, in which case the problem is reported according to theon_problems
setting.
Remarks
Selecting By Type
If selecting by type, then the length, scale and precision are ignored.
In other words, ..Text
will match any text column, regardless of its
length or being fixed or variable length. Similarly, ..Integer
will
match any integer column, regardless of its size.