Skip to main content

Table.reorder_columns

reorder_columnscolumns positioncase_sensitivityerror_on_missing_columnson_problems

Group: Selections

Documentation

Reorders the columns by moving the selected columns to the start (or end) of the Table. By default, the selected columns are moved to the front. Other columns are left in their original order.

Arguments

  • columns: Specifies columns by a name, type, index or regular expression to match names, or a Vector of these.
  • position: Specifies how to place the selected columns in relation to the remaining columns which were not matched by columns (if any).
  • case_sensitivity: Controls whether to be case sensitive when matching column names.
  • error_on_missing_columns: Specifies if a missing input column should result in an error regardless of the on_problems settings. Defaults to False.
  • on_problems: Specifies how to handle problems if they occur, reporting them as warnings by default.

Returns

  • A new table with the columns reordered.

Examples

Move a column with a specified name to back.

      table = Table.from_rows ["bar","foo","buzz","bizz"] [["John", "25","abc","123"]]
output = table.reorder_columns ["foo"] position=..After_Other_Columns

Returns a Table

barbuzzbizzfoo
Johnabc12325

Move columns using names passed as a Vector.

      table = Table.from_rows ["bar","foo","buzz","bizz"] [["John", "25","abc","123"]]
output = table.reorder_columns ["bizz", "foo"]

Returns a Table

bizzfoobarbuzz
12325Johnabc

Move columns matching a regular expression to front, keeping columns matching "f.+" before columns matching "ba.*".

      table = Table.from_rows ["bar","foo","buzz","bizz"] [["John", "25","abc","123"]]
output = table.reorder_columns [(regex "f.+"), (regex "ba.*")] case_sensitivity=..Insensitive

Returns a Table

foobarbuzzbizz
25Johnabc123

Swap the first two columns.

      table = Table.from_rows ["bar","foo","buzz","bizz"] [["John", "25","abc","123"]]
output = table.reorder_columns [1, 0] position=..Before_Other_Columns

Returns a Table

foobarbuzzbizz
25Johnabc123

Move the first column to back.

      table = Table.from_rows ["bar","foo","buzz","bizz"] [["John", "25","abc","123"]]
output = table.reorder_columns [0] position=..After_Other_Columns

Returns a Table

foobuzzbizzbar
25abc123John

Errors

  • If a column in columns is not in the input table, a Missing_Input_Columns is reported according to the on_problems setting, unless error_on_missing_columns is set to True, in which case it is raised as an error.