by_type¶
champalimaud.by_type
¶
Collect the values of a table column for each cell type.
values_by_type(table, column, types)
¶
The values of a column among the rows of each type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
DataFrame
|
Has a column |
required |
column
|
str
|
Column whose values are collected. |
required |
types
|
sequence of str
|
The types to collect, in order. |
required |
Returns:
| Type | Description |
|---|---|
dict of str to polars.Series
|
One series per type; a type with no row has an empty series. |
See Also
champalimaud.overlap.sets_by_type : The same, as sets.
Examples:
>>> import polars as pl
>>> table = pl.DataFrame({"type": ["P", "P", "Q"], "s": [3, 5, 4]})
>>> by_type = values_by_type(table, "s", ["P", "Q"])
>>> {t: values.to_list() for t, values in by_type.items()}
{'P': [3, 5], 'Q': [4]}