-
Notifications
You must be signed in to change notification settings - Fork 11
Sort rows filter
David Megginson edited this page Sep 1, 2015
·
4 revisions
The Sort rows HXL filter reorders the rows in a HXL dataset, into ascending or descending order, based on all columns or specific ones that you select.
- All comparisons are case- and whitespace-insensitive.
- If two values look like numbers, the will try to compare them as numbers rather than strings (so that "20" sorts before "1000" instead of after it).
- You may specify a list of tag patterns to act as sort keys, e.g.
#adm1+name,#adm2+name
- You may specify whether the sort should be reversed (descending order).
Goal: sort the dataset in ascending order by #sector
:
Input:
#org | #sector | #adm1 |
---|---|---|
Org A | WASH | Coast District |
Org B | Health | Mountain District |
Org C | Education | Plains District |
Output:
#org | #sector | #adm1 |
---|---|---|
Org C | Education | Plains District |
Org B | Health | Mountain District |
Org A | WASH | Coast District |
Use the hxlsort program (hxlsort -h
for help):
hxlsort --tags sector dataset-in.csv
Use the sort filter method:
hxl.data(url).sort()
You can supply a single tag or a list of tags:
hxl.data(url).sort('sector')
hxl.data(url).sort(['sector', 'org'])
In the HXL Proxy, choose the "Sort rows" filter type. You can (optionally) enter a comma-separate list of column tags for sorting, and flag for reverse sort order.
Standard: http://hxlstandard.org | Mailing list: hxlproject@googlegroups.com