# DataFrames: obtaining the subset of rows by a set of values

**URL:** https://discourse.julialang.org/t/dataframes-obtaining-the-subset-of-rows-by-a-set-of-values/15923
**Category:** New to Julia
**Tags:** dataframes
**Created:** [October 5, 2018, 1:14pm UTC](https://discourse.julialang.org/t/dataframes-obtaining-the-subset-of-rows-by-a-set-of-values/15923 "2018-10-05T13:14:50Z")
**Posts on this page:** 6
**Page:** 3

<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: [October 18, 2018, 3:49pm UTC](https://discourse.julialang.org/t/dataframes-obtaining-the-subset-of-rows-by-a-set-of-values/15923/41 "2018-10-18T15:49:31Z")

</div>

> ```
> iris |> 
> Filter(Species -> Species == "versicolor") |>
> Map((SepalLength, SepalWidth) -> SepalLength / SepalWidth)
> 
> ```

This scares me a bit because it means that fast filtering would have to happen with variables themselves, named in the code, instead of with functions, due to the non-standard evaluation. It’s an R-ism that I want to avoid if possible.

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [November 17, 2018, 4:43pm UTC](https://discourse.julialang.org/t/dataframes-obtaining-the-subset-of-rows-by-a-set-of-values/15923/42 "2018-11-17T16:43:26Z")

</div>

I’ve opened a WIP PR in DataFrames about using the `select` approach for combining results of a grouping operations: [https://github.com/JuliaData/DataFrames.jl/pull/1601](https://github.com/JuliaData/DataFrames.jl/pull/1601)

---

<div class="post-metadata">

### Author: ![josimar](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@josimar](https://discourse.julialang.org/u/josimar)
#### Post date: [December 5, 2022, 3:56pm UTC](https://discourse.julialang.org/t/dataframes-obtaining-the-subset-of-rows-by-a-set-of-values/15923/43 "2022-12-05T15:56:35Z")

</div>

Could you please clarify how to type in the Greek symbol on the REPL?

I tried \epsilon but this is not the correct symbol.

I mean the symbol that is written here: filter(row → row.col ∈ [1,2,3], df)

Thanks!

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [December 5, 2022, 4:16pm UTC](https://discourse.julialang.org/t/dataframes-obtaining-the-subset-of-rows-by-a-set-of-values/15923/44 "2022-12-05T16:16:28Z")

</div>

`\in`

---

<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 6, 2022, 9:55am UTC](https://discourse.julialang.org/t/dataframes-obtaining-the-subset-of-rows-by-a-set-of-values/15923/45 "2022-12-06T09:55:48Z")

</div>

When in doubt ask the REPL:

```julia
help?> ζ
"ζ" can be typed by \zeta<tab>

help?> ∈
"∈" can be typed by \in<tab>

```

---

<div class="post-metadata">

### Author: ![merlin](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@merlin](https://discourse.julialang.org/u/merlin)
#### Post date: [April 27, 2024, 9:32pm UTC](https://discourse.julialang.org/t/dataframes-obtaining-the-subset-of-rows-by-a-set-of-values/15923/46 "2024-04-27T21:32:33Z")

</div>

That `∈([1,2,3]).(df.col)` is some niiiiice syntax!

Specifically, nice for getting row number or index to create a `@view` of a dataframe. Views cant be made from the dataframe output of a `filter` or `subset` operation. This had me stumped for a while.

For example, I need to change the cells in column `:X2` if the rows in column `label` match a string:

```jl
df_vw = @view df[∈(["label_p", "label_t", "label_w"]).(df.label), [:X1, :X2]]

# X1 is fraction, make into bips and update cell in :X2
transform!(df_vw, :X1 => ByRow(x -> string(round(Int, x * 100000), " bps")) => :X2)

# alternately with direct assignment:
df_vw[:, :X2 = string.(round.(Int, df_vw[:, :X1] * 10000), " bps")

```

Thanks again, @ExpandingMan !!!

```julia

```

[Previous page](https://discourse.julialang.org/t/dataframes-obtaining-the-subset-of-rows-by-a-set-of-values/15923.md?page=2)
