Skip to main content

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 a By_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 to False, columns in the output will be in the same order as in the input table. If True, 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 the on_problems settings. Defaults to True.
  • 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

barfoo
John25

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

foobar
25John

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

barbuzzbizz
Johnabc123

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

bizzbarfoo
123John25

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

foobizz
25123

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, a Missing_Input_Columns is raised as an error, unless error_on_missing_columns is set to False, in which case the problem is reported according to the on_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.