Built-in transforms
Everything here is a thin wrapper over the one-row-in, rows-out contract.
| Transform | Signature | Purpose |
|---|---|---|
select | select(*cols) | Keep only the named columns, in the given order. |
drop | drop(*cols) | Remove the named columns. |
rename | rename(**old_to_new) | Rename columns. |
where | where(pred) | Keep rows for which pred(row) is truthy. |
derive | derive(**col_to_fn) | Add or replace columns from functions of the row. |
fill | fill(**col_to_default) | Replace empty values with a default. |
dedupe | dedupe(*keys) | Drop repeat rows sharing the same key columns. |
chunk | chunk(n) | Group the stream into lists of up to n rows. |
Writing your own
If none of the above fit, write a function. Anything that yields rows composes with the built-ins:
from larkspur import Frame
def split_tags(row):
for tag in row["tags"].split(";"):
yield {**row, "tag": tag.strip()}
Frame.read_csv("posts.csv") | split_tags | select("id", "tag")