Skip to main content

Sort Table

Sorts a data table based on the values in a specified column.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Table - The input data table to be sorted.
  • Column Name - The name of the column to sort by.

Options

  • Order Type - Specifies the sort order. Options are:
    • Ascending - Sort in ascending order (A-Z, 0-9)
    • Descending - Sort in descending order (Z-A, 9-0)
  • Output Type - Specifies whether to pass the table by reference or by value. Options are:
    • Pass By Reference
    • Pass By Value
  • Locale - Optional. Specifies the locale to use for sorting string values.

Output

  • Table - The resulting sorted data table.

How It Works

The Sort Table node sorts a data table based on the values in a specified column. When executed, the node:

  1. Validates that the input table is not empty and is valid
  2. Checks if the table is a reference table and handles it appropriately
  3. Validates that the column name is not empty
  4. Converts the data table to a pandas DataFrame
  5. Sorts the DataFrame based on the specified column and options
  6. Converts the sorted DataFrame back to the data table format
  7. Returns the sorted table

Requirements

  • A valid input data table
  • A valid column name that exists in the table

Error Handling

The node will return specific errors in the following cases:

  • Empty or invalid input table
  • Empty column name
  • Invalid table structure
  • Column name does not exist in the table

Usage Notes

  • The Output Type option can be set to "Pass By Reference" for handling large tables more efficiently
  • The Order Type option determines whether the table is sorted in ascending or descending order
  • The Locale option can be used to specify locale-specific sorting rules for string values
  • The node sorts the entire table based on the values in the specified column
  • All rows in the table maintain their integrity during the sorting process

Usage Examples

Example 1: Sort by a Column Ascending

- CSV To Data Table (sales.csv) -> table
- Sort Table:
- Table: table
- Column Name: amount
- Order Type: True
- Table (out): table
- Data Table To CSV (table, sorted.csv)

In the SDK:

.then('a06926', 'Robomotion.Pandas.SortTable', 'Sort by Amount', {
inTable: Message('table'),
inColumnName: Custom('amount'),
optAscending: 'True',
outTable: Message('table')
})

Example 2: Sort Descending to Find the Largest Values

.then('b17c34', 'Robomotion.Pandas.SortTable', 'Biggest First', {
inTable: Message('table'),
inColumnName: Custom('revenue'),
optAscending: 'False',
outTable: Message('table')
})

Example 3: Locale-Aware String Sorting

Sorting names with accented characters uses the locale rather than raw byte order:

.then('c28d45', 'Robomotion.Pandas.SortTable', 'Sort Names', {
inTable: Message('table'),
inColumnName: Custom('surname'),
optLocale: Custom('de_DE.UTF-8'),
outTable: Message('table')
})

Example 4: Sort a Large Table by Reference

For tables too large to pass by value between nodes:

.then('d39e56', 'Robomotion.Pandas.SortTable', 'Sort Big Table', {
inTable: Message('table'),
inColumnName: Custom('timestamp'),
optReference: 'True',
outTable: Message('table')
})

Tips

  • Order Type is the string True or False, not a boolean. optAscending: 'True' is correct; optAscending: true will not parse. The same applies to Output Type (optReference).
  • The column name must match a column in the table exactly, including case
  • Sorting a numeric column that arrived from CSV as text sorts lexically (10 before 9) - use Convert Type first if the source is a CSV
  • Pass By Reference avoids copying the table between nodes and is worth using once tables get large; the trade-off is that downstream nodes see the same underlying table
  • To sort by more than one column, chain two Sort Table nodes, least significant first
  • Every node in this package expects the standard table shape ({columns: [...], rows: [{key: value}]}), so build tables with a Function node before sorting