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 bycolumns(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 theon_problemssettings. Defaults toFalse.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
| bar | buzz | bizz | foo |
|---|---|---|---|
| John | abc | 123 | 25 |
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
| bizz | foo | bar | buzz |
|---|---|---|---|
| 123 | 25 | John | abc |
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
| foo | bar | buzz | bizz |
|---|---|---|---|
| 25 | John | abc | 123 |
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
| foo | bar | buzz | bizz |
|---|---|---|---|
| 25 | John | abc | 123 |
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
| foo | buzz | bizz | bar |
|---|---|---|---|
| 25 | abc | 123 | John |
Errors
- If a column in
columnsis not in the input table, aMissing_Input_Columnsis reported according to theon_problemssetting, unlesserror_on_missing_columnsis set toTrue, in which case it is raised as an error.