Remove samples/rows from anndata

I can see how to remove columns from anndata ie

keep = ['a','b','c']

adata = adata [:, keep]

How does one remove rows/sets of samples from anndata.obs and anndata.x?

for example remove adata.obs[Region='reg012']

adata.obs

enter image description here

Everything is connected, so you can’t remove rows from .obs without removing rows from the whole object. In your case you want to do one of the following:

adata[adata.obs["Region"] != "reg012"]
adata[adata.obs.query("Region != 'reg012'").index]
adata[[r != "reg012" for r in adata.obs.Region]]
1 Like