Larkspur tabular transforms, kept small

Built-in transforms

Everything here is a thin wrapper over the one-row-in, rows-out contract.

TransformSignaturePurpose
selectselect(*cols)Keep only the named columns, in the given order.
dropdrop(*cols)Remove the named columns.
renamerename(**old_to_new)Rename columns.
wherewhere(pred)Keep rows for which pred(row) is truthy.
derivederive(**col_to_fn)Add or replace columns from functions of the row.
fillfill(**col_to_default)Replace empty values with a default.
dedupededupe(*keys)Drop repeat rows sharing the same key columns.
chunkchunk(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")