Skip to main content

DB_Table.reorder_columns

reorder_columnscolumns positioncase_sensitivityerror_on_missing_columnson_problems

Group: Selections

Documentation

Returns a new table with the specified selection of columns moved to either the start or the end in the specified 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.

Examples

Move a column with a specified name to back.

      table.reorder_columns ["foo"] position=Position.After_Other_Columns

Move columns using names passed as a Vector.

      table.reorder_columns ["bar", "foo"] position=Position.After_Other_Columns

Move columns matching a regular expression to front, keeping columns matching "foo.+" before columns matching "b.*".

      table.reorder_columns "foo.+".to_regex case_sensitivity=Case_Sensitivity.Insensitive

Swap the first two columns.

      table.reorder_columns [1, 0]

Move the first column to back.

      table.reorder_columns [0] position=Position.After_Other_Columns

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.