annsel.AnnselAccessor.group_by#
- AnnselAccessor.group_by(self, obs=None, var=None, copy=False)[source]#
Group the AnnData object by the given predicates.
- Parameters:
- obs
Expr|str|Series|Iterable[Expr|str|Series] |None(default:None) Predicates to group the observations by.
- var
Expr|str|Series|Iterable[Expr|str|Series] |None(default:None) Predicates to group the variables by.
- copy
bool(default:False) Whether to return a copy of the AnnData object when grouping. If obs and var are both None, returns a copy of the original AnnData object if True, otherwise returns the original object.
- obs
- Return type:
- Returns:
The original AnnData object (or a copy) if both
obsandvarareNone. Otherwise, returns a generator that yieldsGroupByAnndataobjects for each group.
Examples
>>> import annsel as an >>> adata = an.datasets.leukemic_bone_marrow_dataset() >>> groups = adata.an.group_by( ... obs=an.col(["Cell_label", "sex"]), ... var=an.col(["feature_name"]), ... ) >>> for group in groups: ... print(group.obs_dict, group.var_dict)