prose¶
champalimaud.prose
¶
Phrases built from a table, to quote it in a sentence.
A list joined with commas and "and", and the smallest and largest value of a column with their labels.
and_list(items)
¶
Join items as a phrase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
sequence of str
|
The items, in order. |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Examples:
Source code in champalimaud/prose.py
span_of(table, column, *, by='type', fmt='')
¶
Quote the smallest and largest value of a column, with labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
DataFrame
|
Has |
required |
column
|
str
|
Column whose smallest and largest value are quoted. |
required |
by
|
str
|
Column that labels each row. |
"type"
|
fmt
|
str
|
Format spec of the values, such as |
""
|
Returns:
| Type | Description |
|---|---|
str
|
For example |
See Also
value_list : Every row, not only the ends.
Examples:
>>> import polars as pl
>>> table = pl.DataFrame(
... {
... "type": ["A", "B", "C"],
... "share": [0.08, 0.13, 0.11],
... }
... )
>>> span_of(table, "share", fmt=".0%")
'8% (A) to 13% (B)'
Source code in champalimaud/prose.py
value_list(table, column, *, by='type', fmt='', template='{label} {value}')
¶
Quote the rows of a table as a phrase, one value per row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
DataFrame
|
Has |
required |
column
|
str
|
Column whose value is quoted for each row. |
required |
by
|
str
|
Column that labels each row. |
"type"
|
fmt
|
str
|
Format spec of the values. |
""
|
template
|
str
|
Text for one row, filled with |
"{label} {value}"
|
Returns:
| Type | Description |
|---|---|
str
|
The rows in order, joined as |
See Also
span_of : Only the smallest and the largest.
Examples:
>>> import polars as pl
>>> table = pl.DataFrame(
... {
... "type": ["A", "B", "C"],
... "share": [0.08, 0.13, 0.11],
... }
... )
>>> value_list(table, "share", fmt=".0%")
'A 8%, B 13%, and C 11%'