Skip to main content

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 the on_problems settings. Defaults to True.
  • 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

NameQuantity
Paul3
John5

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

NameQuantity
Paul3
John5

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

NameQuantityRating
Paul35
John53

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

NameQuantityRating
John53
Paul35

Errors

  • If a column in columns is not in the input table, a Missing_Input_Columns is raised as an error, unless error_on_missing_columns is set to False, in which case the problem is reported according to the on_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.