This page describes table manipulation functions docs ↗ that allow you to sort, filter, and compute values from any kind of table, including plain Markdown ones and those loaded from CSV.
.tablesort {2} order:{descending}
.csv {assets/people.csv}| Username | Birth year | Favorite food | Favorite drink |
|---|---|---|---|
| iamgio | 2002 | Pasta | Iced tea |
| john | 1992 | Chicken | Orange juice |
| daniel | 1986 | Sushi | Beer |
The .tablesort function sorts a table based on the values of a specific column.
| Parameter | Description | Accepts |
|---|---|---|
column | Index of the column, starting from 1. | 1 to number of columns. |
order | Sorting order. | ascending (default), descending |
.tablesort {2} order:{descending}
| Name | Age | City |
|------|-----|------|
| John | 25 | NY |
| Lisa | 32 | LA |
| Mike | 19 | CHI || Name | Age | City |
|---|---|---|
| Lisa | 32 | LA |
| John | 25 | NY |
| Mike | 19 | CHI |
The sorting follows the most natural way for humans to sort strings (alphanumeric sorting):
.tablesort {2}
| Item | Price |
|----------|-------|
| Pencil | $1 |
| Eraser | $0.50 |
| Backpack | $20 |
| Notebook | $3 || Item | Price |
|---|---|
| Eraser | $0.50 |
| Pencil | $1 |
| Notebook | $3 |
| Backpack | $20 |
The .tablefilter function keeps or removes rows based on the values of a specific column.
| Parameter | Description | Accepts |
|---|---|---|
column | Index of the column, starting from 1. | 1 to number of columns. |
filter | Lambda that returns whether each row should be kept, with the value of its cell in the corresponding column as input. | Dynamic → Boolean lambda |
.tablefilter {2} {@lambda x: .x::isgreater {20}}
| Name | Age | City |
|------|-----|------|
| John | 25 | NY |
| Lisa | 32 | LA |
| Mike | 19 | CHI || Name | Age | City |
|---|---|---|
| John | 25 | NY |
| Lisa | 32 | LA |
The .tablecompute function computes the cells in a column and appends the result to a new row.
| Parameter | Description | Accepts |
|---|---|---|
column | Index of the column, starting from 1. | 1 to number of columns. |
compute | Lambda that returns the computed value, with the collection of the cells in the column as input. | Iterable → Dynamic lambda |
See Iterable to learn more about available operations on collections.
.tablecompute {2} {@lambda x: .x::average::round}
| Name | Age | City |
|------|-----|------|
| John | 25 | NY |
| Lisa | 32 | LA |
| Mike | 19 | CHI || Name | Age | City |
|---|---|---|
| John | 25 | NY |
| Lisa | 32 | LA |
| Mike | 19 | CHI |
| 25 |
You can chain multiple table operations. The order of operations goes from inner to outer:
.tablecompute {2} {@lambda x: .x::average::round}
.tablesort {2}
| Name | Age | City |
|------|-----|------|
| John | 25 | NY |
| Lisa | 32 | LA |
| Mike | 19 | CHI || Name | Age | City |
|---|---|---|
| Mike | 19 | CHI |
| John | 25 | NY |
| Lisa | 32 | LA |
| 25 |
The .tablecolumn function extracts values from the cells of a specific column and returns them as an Iterable.
| Parameter | Description | Accepts |
|---|---|---|
column | Index of the column, starting from 1. | 1 to number of columns. |
.var {values}
.tablecolumn {2}
| Name | Age | City |
|------|-----|------|
| John | 25 | NY |
| Lisa | 32 | LA |
| Mike | 19 | CHI |
.values::first25
Additionally, the .tablecolumns function returns all the columns from the table as an iterable of iterables. This is more efficient when you need to access multiple columns from the same table, compared to calling .tablecolumn multiple times.
.var {columns}
.tablecolumns
| Name | Age | City |
|------|-----|------|
| John | 25 | NY |
| Lisa | 32 | LA |
| Mike | 19 | CHI |
.foreach {.columns}
col:
.col::firstJohn
25
NY