by_type¶
lab.connectome.by_type
¶
Collect the values of a table column for each cell type.
in_order(table, order, *, by='type')
¶
Sort the rows of a table by the position of their label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
DataFrame
|
Has the column named by |
required |
order
|
sequence of str
|
The labels in the order the rows should come. |
required |
by
|
str
|
Column that holds each row's label. |
"type"
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The rows sorted by the position of their |
Examples:
>>> import polars as pl
>>> table = pl.DataFrame({"type": ["B", "A", "C"], "n": [1, 2, 3]})
>>> in_order(table, ["A", "B"])["type"].to_list()
['A', 'B', 'C']
Source code in lab/connectome/by_type.py
values_by_type(table, column, types)
¶
Collect 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
lab.connectome.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]}