# Selecting samples from a list of IDs from a matrixTable

**URL:** <https://discuss.hail.is/t/selecting-samples-from-a-list-of-ids-from-a-matrixtable/3543>\
**Category:** Hail Query & hailctl\
**Created:** [August 9, 2023, 8:04pm UTC](https://discuss.hail.is/t/selecting-samples-from-a-list-of-ids-from-a-matrixtable/3543 "2023-08-09T20:04:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![j-mitra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/j-mitra/32/996_2.png) [@j-mitra](https://discuss.hail.is/u/j-mitra)\
**Post date:** [August 9, 2023, 8:04pm UTC](https://discuss.hail.is/t/selecting-samples-from-a-list-of-ids-from-a-matrixtable/3543/1 "2023-08-09T20:04:50Z")

</div>

Hello world,

I have just started getting my feet wet in Hail, and already have stumbled upon an issue I need help with.  
I want to select a subset of samples from my hail `matrixTable`, from a list of sample IDs.  
I tried some solutions mentioned in previous posts, but I keep getting an error.  
I tried running:

```python
filtered_mt = mt.filter_cols(hl.array(selectedIndividuals['ID']).contains(mt.s))

```

This gives me an error that says:

```python
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

```

I’m sure I’m missing something quite simple here. Can anyone in the Hail community please help me out with this?

Thanks in advance,  
Joy

---

<div class="post-metadata">

**Author:** ![iris-garden](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/iris-garden/32/828_2.png) [@iris-garden](https://discuss.hail.is/u/iris-garden)\
**Post date:** [August 10, 2023, 2:49pm UTC](https://discuss.hail.is/t/selecting-samples-from-a-list-of-ids-from-a-matrixtable/3543/2 "2023-08-10T14:49:14Z")

</div>

hi joy,

i think i need a little more information to help out here. what does `selectedIndividuals` look like? feel free to replace the actual data with example data; i just need to see what the type and structure of it is.

–iris

---

<div class="post-metadata">

**Author:** ![j-mitra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/j-mitra/32/996_2.png) [@j-mitra](https://discuss.hail.is/u/j-mitra)\
**Post date:** [August 14, 2023, 7:22pm UTC](https://discuss.hail.is/t/selecting-samples-from-a-list-of-ids-from-a-matrixtable/3543/3 "2023-08-14T19:22:03Z")

</div>

Hi @iris-garden ,  
Thanks for your reply. `selectedIndividuals` is a pandas dataframe, with the sample identifiers in the “ID” column.  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/hail/original/2X/3/309b620219106a74f18fea12dd91a16b7ed6ea4e.png)  
I want to subset the matrixTable mt with only the samples listed in the ‘ID’ column.

Thanks again for the help. Let me know if any other details might help.

Best,  
Joydeep

---

<div class="post-metadata">

**Author:** ![iris-garden](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/iris-garden/32/828_2.png) [@iris-garden](https://discuss.hail.is/u/iris-garden)\
**Post date:** [August 15, 2023, 7:35pm UTC](https://discuss.hail.is/t/selecting-samples-from-a-list-of-ids-from-a-matrixtable/3543/4 "2023-08-15T19:35:02Z")

</div>

okay, looks like the issue is that we’re not able to directly convert a pandas `DataFrame` column into a hail `array`. one option would be to convert the column to a Python `list` first:

```python
filtered_mt = mt.filter_cols(
    hl.array(selectedIndividuals['ID'].tolist()).contains(mt.s)
)

```

but if your `DataFrame` has a lot of values, that might end up being slow, so instead you could convert the `DataFrame` to a hail `Table`, and filter using that instead:

```python
# convert the whole DataFrame:
ht = hl.Table.from_pandas(selectedIndividuals)

# or convert just the ID column, if you'd prefer:
ids = pd.DataFrame
ids["ID"] = selectedIndividuals["ID"]
ht = hl.Table.from_pandas(ids)

# filter using the Table we just created
mt = mt.filter_cols(hl.is_defined(ht[mt.s]))

```

hope that helps!
