from tinytab import Table, fmt_currency
tbl = Table({"item": ["coffee", "bagel"], "price": [3.5, 2.25]})
tbl.fmt("price", fmt_currency)| item | price |
|---|---|
| coffee | $3.50 |
| bagel | $2.25 |
Attach a formatting function to a column.
Usage
column: strThe column to format.
fn: Callable[[Any], str]None) are rendered as empty cells and are never passed to fn.
TableFormat the price column as US dollars:
from tinytab import Table, fmt_currency
tbl = Table({"item": ["coffee", "bagel"], "price": [3.5, 2.25]})
tbl.fmt("price", fmt_currency)| item | price |
|---|---|
| coffee | $3.50 |
| bagel | $2.25 |
Any function that takes a value and returns a string works as a formatter: