Table.sort
sortcolumnstext_orderingerror_on_missing_columnson_problems
Group: Selections
Aliases: order_by
Documentation
Sorts the rows of the table by specified columns.
Optionally, the method of ordering text values can be specified allowing for case-insensitively or dictionary ordering.
Arguments
columns: The columns and order to sort the table.text_ordering: The ordering method to use on text values.error_on_missing_columns: Specifies if a missing input column should result in an error regardless of theon_problemssettings. Defaults toTrue.on_problems: Specifies how to handle problems if they occur, reporting them as warnings by default.
Returns
- A new table with the rows sorted as specified.
Examples
Sorting table in ascending order by the value in column 'Quantity'.
table = Table.from_rows ["Name","Quantity"] [["John", 5],["Paul", 3]]
sorted = table.sort ['Quantity']
Returns a Table
| Name | Quantity |
|---|---|
| Paul | 3 |
| John | 5 |
Sorting table in descending order by the value in column 'Name'.
table = Table.from_rows ["Name","Quantity"] [["John", 5],["Paul", 3]]
sorted = table.sort [..Name 'Name' ..Descending]
Returns a Table
| Name | Quantity |
|---|---|
| Paul | 3 |
| John | 5 |
Sorting table in ascending order by the value in column 'Quantity',
using the value in column 'Rating' for breaking ties.
table = Table.from_rows ["Name","Quantity","Rating"] [["John", 5, 3],["Paul", 3, 5]]
sorted = table.sort ['Quantity', 'Rating']
Returns a Table
| Name | Quantity | Rating |
|---|---|---|
| Paul | 3 | 5 |
| John | 5 | 3 |
Sorting table in ascending order by the value in column 'Quantity',
using the value in column 'Rating' in descending order for breaking
ties.
table = Table.from_rows ["Name","Quantity","Rating"] [["John", 5, 3],["Paul", 3, 5]]
sorted = table.sort ['Quantity', ..Name 'Rating' ..Descending]
Returns a Table
| Name | Quantity | Rating |
|---|---|---|
| John | 5 | 3 |
| Paul | 3 | 5 |
Errors
- If a column in
columnsis not in the input table, aMissing_Input_Columnsis raised as an error, unlesserror_on_missing_columnsis set toFalse, in which case the problem is reported according to theon_problemssetting. - If no columns have been selected for ordering, a
No_Input_Columns_Selectedis raised as dataflow error regardless of any settings. - If a column used for ordering contains values that cannot be compared,
an
Incomparable_Valueserror is raised.
Remarks
Missing Values
Missing (Nothing) values are sorted as less than any other object.