anndata_rs.AnnData.split_by

AnnData.split_by(key, out_dir='./')

Split the AnnData object into multiple AnnData objects based on grouping keys. The length of the grouping keys must match the number of observations.

Parameters:
  • key (str | list[str]) – Grouping key(s). Can be a single column name or a list of column names in obs.

  • out_dir (Path) – Output directory to save the split AnnData files.

Returns:

A dictionary mapping each unique key to its corresponding AnnData object.

Return type:

dict[str, AnnData]