craftutils.wrap.dragons.Table.sort(keys=None, *, kind=None, reverse=False)

Sort the table according to one or more keys. This operates on the existing table and does not return a new table.

Parameters

keysstr or list of str

The key(s) to order the table by. If None, use the primary index of the Table.

kind{‘quicksort’, ‘mergesort’, ‘heapsort’, ‘stable’}, optional

Sorting algorithm used by numpy.argsort.

reversebool

Sort in reverse order (default=False)

Examples

Create a table with 3 columns:

>>> t = Table([['Max', 'Jo', 'John'], ['Miller', 'Miller', 'Jackson'],
...            [12, 15, 18]], names=('firstname', 'name', 'tel'))
>>> print(t)
firstname   name  tel
--------- ------- ---
      Max  Miller  12
       Jo  Miller  15
     John Jackson  18

Sorting according to standard sorting rules, first ‘name’ then ‘firstname’:

>>> t.sort(['name', 'firstname'])
>>> print(t)
firstname   name  tel
--------- ------- ---
     John Jackson  18
       Jo  Miller  15
      Max  Miller  12

Sorting according to standard sorting rules, first ‘firstname’ then ‘tel’, in reverse order:

>>> t.sort(['firstname', 'tel'], reverse=True)
>>> print(t)
firstname   name  tel
--------- ------- ---
      Max  Miller  12
     John Jackson  18
       Jo  Miller  15