Skip to content

TableSorting(keys) Source

Columns the rows of a Table are sorted by, used by Table.sort.

Rows are sorted by the first key, then rows with the same value by the second key, and so on. Rows equal on every key keep their order.

Changed in version 0.2.0

Renamed from Sorting.

Version history (1)

Added in version 0.1.0

Parameters:

  • keys (list[SortKey])

    The sort keys, at least one, each on a different column. The sorting keeps its own copy of the list.

Raises:

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Paris", "Lyon", "Paris"])
prices = ndp.Array.from_list([120.0, 80.0, 150.0])
sales = ndp.Table.from_arrays({"city": cities, "price": prices})
by_city = ndp.SortKey(column="city")
by_price = ndp.SortKey(column="price", order=ndp.Order.DESCENDING)
sales.sort(ndp.TableSorting(keys=[by_city, by_price]))
#     city   price
#     TEXT FLOAT64
# 0   Lyon    80.0
# 1  Paris   150.0
# 2  Paris   120.0