# DataFrame isin operation

**URL:** https://discourse.julialang.org/t/dataframe-isin-operation/72825
**Category:** New to Julia
**Tags:** dataframes
**Created:** [December 9, 2021, 1:29pm UTC](https://discourse.julialang.org/t/dataframe-isin-operation/72825 "2021-12-09T13:29:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![gjh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gjh/32/31762_2.png) [@gjh](https://discourse.julialang.org/u/gjh)
#### Post date: [December 9, 2021, 1:29pm UTC](https://discourse.julialang.org/t/dataframe-isin-operation/72825/1 "2021-12-09T13:29:11Z")

</div>

Is there a function that would allow selecting rows/columns with isin?

df = DataFrame(Column1 = [“a”, "b, “c”, “d”, “e”, “f”],  
Column2 = [1, 2, 3, 1, 2, 3],  
)  
keep = [“a”, “c”, “e”]  
df[isin(df.Column1, keep), :]

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [December 9, 2021, 1:33pm UTC](https://discourse.julialang.org/t/dataframe-isin-operation/72825/2 "2021-12-09T13:33:13Z")

</div>

There is a function to do this. You would just need to do

```julia
in.(df.Column1, Ref(keep))

```

_but_ with questions like these, usually what people really need is an `innerjoin`.

---

<div class="post-metadata">

### Author: ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)
#### Post date: [December 9, 2021, 1:52pm UTC](https://discourse.julialang.org/t/dataframe-isin-operation/72825/3 "2021-12-09T13:52:46Z")

</div>

or `in.(df.Column1, Ref(Set(keep)))` if `keep` and `:Column1` are long and performance matters.

However, as @pdeffebach commented `innerjoin` is optimized to do such operations efficiently (e.g. if your data would be sorted it would take advantage of this fact and such thing is ignored by `in`).

---

<div class="post-metadata">

### Author: ![gjh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gjh/32/31762_2.png) [@gjh](https://discourse.julialang.org/u/gjh)
#### Post date: [December 9, 2021, 3:23pm UTC](https://discourse.julialang.org/t/dataframe-isin-operation/72825/4 "2021-12-09T15:23:47Z")

</div>

thank you both!

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [December 9, 2021, 3:55pm UTC](https://discourse.julialang.org/t/dataframe-isin-operation/72825/5 "2021-12-09T15:55:31Z")

</div>

I won’t let one of these threads go by without mentioning my favourite use of the Fix2 syntax:

```julia
in(keep).(df.Column1)

```

(or `Set(keep)` as Bogumil said)
