Table.sort
sortcolumns text_orderingerror_on_missing_columnson_problems
Group: Selections
Aliases: order_by
Documentation
Reorders the table by sorting them based on the 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_problems
settings. 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
columns
is not in the input table, aMissing_Input_Columns
is raised as an error, unlesserror_on_missing_columns
is set toFalse
, in which case the problem is reported according to theon_problems
setting. - If no columns have been selected for ordering,
a
No_Input_Columns_Selected
is raised as dataflow error regardless of any settings. - If a column used for ordering contains values that cannot be
compared, an
Incomparable_Values
error is raised.
Remarks
Missing Values
Missing (Nothing
) values are sorted as less than any other object.