# Unable to remove cells from Anndata matrix by an added .obs

**URL:** <https://discourse.scverse.org/t/unable-to-remove-cells-from-anndata-matrix-by-an-added-obs/1552>\
**Category:** Help\
**Created:** [June 27, 2023, 4:05am UTC](https://discourse.scverse.org/t/unable-to-remove-cells-from-anndata-matrix-by-an-added-obs/1552 "2023-06-27T04:05:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qtasnim](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/qtasnim/32/464_2.png) [@Qtasnim](https://discourse.scverse.org/u/Qtasnim)\
**Post date:** [June 27, 2023, 4:05am UTC](https://discourse.scverse.org/t/unable-to-remove-cells-from-anndata-matrix-by-an-added-obs/1552/1 "2023-06-27T04:05:14Z")

</div>

Hello,

Sorry if the title is not clear!

I have an anndata object:

```auto
adata
Out[10]: 
AnnData object with n_obs × n_vars = 13779 × 36601
    obs: 'doublet', 'doublet_score'
    var: 'gene_ids', 'feature_types'

```

I used DoubletDetection package to detect dublets in my reads matrix after creating the Anndata object immediately (before filtering or qc), and added the results to .obs like this:

```auto
import doubletdetection

clf = doubletdetection.BoostClassifier() 
doublets = clf.fit(adata.X).predict()
adata.obs['doublet'] = doublets
doublet_score = clf.doublet_score()
adata.obs['doublet_score'] = doublet_score

```

After detecting doublets it gives result as “0” for not a doublet and “1” for a doublet.

```auto
adata.obs['doublet'].value_counts()
Out[3]: 
0.0 12697
1.0 1074
Name: doublet, dtype: int64

```

What I want to do is remove all cells that have doublet value of “1” before continuing the rest of the analsysis, what I’ve tried to do is:

```auto
adata= adata[adata.obs["doublet"].isin[('0')],:]
or 
adata= adata[~adata.obs["doublet"].isin[('1')],:]

```

However, it does not remove doublets but either removes all cells or keep all cells

```auto
Out[38]: 
View of AnnData object with n_obs × n_vars = 0 × 36601
    obs: 'doublet', 'doublet_score'
    var: 'gene_ids', 'feature_types'

Out[42]: 
View of AnnData object with n_obs × n_vars = 13779 × 36601
    obs: 'doublet', 'doublet_score'
    var: 'gene_ids', 'feature_types'

```

How can I filter those cells? Is there a manual way like extracting the matrix with doublets data as a csv and deleting cells, then reading again?

Thanks in advance…

---

<div class="post-metadata">

**Author:** ![danamcc](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@danamcc](https://discourse.scverse.org/u/danamcc)\
**Post date:** [June 27, 2023, 7:18pm UTC](https://discourse.scverse.org/t/unable-to-remove-cells-from-anndata-matrix-by-an-added-obs/1552/2 "2023-06-27T19:18:44Z")

</div>

Have you checked the type of values in adata.obs.doublet? Currently you are filtering based on matching the string “0” or “1”, but you might need to do this with a regular integer 0/1.  
I would do something like:  
adata = adata[adata.obs[‘doublet’] == 0].copy()  
I hope this helps!

---

<div class="post-metadata">

**Author:** ![Qtasnim](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/qtasnim/32/464_2.png) [@Qtasnim](https://discourse.scverse.org/u/Qtasnim)\
**Post date:** [June 28, 2023, 12:55am UTC](https://discourse.scverse.org/t/unable-to-remove-cells-from-anndata-matrix-by-an-added-obs/1552/3 "2023-06-28T00:55:41Z")

</div>

Hi.

That worked!!! thank you very much.  
Yes, I have been treating it as a string!  
Thanks a lot.
