# Conditionally sample example from the dataset

**URL:** <https://discuss.huggingface.co/t/conditionally-sample-example-from-the-dataset/12233>\
**Category:** 🤗Datasets\
**Created:** [November 24, 2021, 9:01am UTC](https://discuss.huggingface.co/t/conditionally-sample-example-from-the-dataset/12233 "2021-11-24T09:01:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![macabdul9](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/macabdul9/32/3302_2.png) [@macabdul9](https://discuss.huggingface.co/u/macabdul9)\
**Post date:** [November 24, 2021, 9:01am UTC](https://discuss.huggingface.co/t/conditionally-sample-example-from-the-dataset/12233/1 "2021-11-24T09:01:29Z")

</div>

How how to conditionally sample example from the dataset. Eg dataset.sample(‘id’==‘abc’)?

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [November 24, 2021, 11:00am UTC](https://discuss.huggingface.co/t/conditionally-sample-example-from-the-dataset/12233/2 "2021-11-24T11:00:30Z")

</div>

This is also referred to as filtering the dataset, docs can be found here: [Main classes — datasets 1.15.1 documentation](https://huggingface.co/docs/datasets/package_reference/main_classes.html?highlight=filter#datasets.Dataset.filter)
