# DataFrame element-wise equality filter

**URL:** https://discourse.julialang.org/t/dataframe-element-wise-equality-filter/11070
**Category:** General Usage
**Tags:** dataframes
**Created:** [May 22, 2018, 10:08am UTC](https://discourse.julialang.org/t/dataframe-element-wise-equality-filter/11070 "2018-05-22T10:08:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)
#### Post date: [May 22, 2018, 10:08am UTC](https://discourse.julialang.org/t/dataframe-element-wise-equality-filter/11070/1 "2018-05-22T10:08:40Z")

</div>

I’m probably missing something super obvious, but I can’t figure out why the filtering of the `DataFrame` doesn’t work as expected in this example (I’m expecting the filtering to return the row as the `code` value is the same):

```julia
genie> hotel_matches
genie> 1×4 DataFrames.DataFrame
│ Row │ code │ address_relevance │ name_relevance │ stars_relevance │
├─────┼────────┼───────────────────┼────────────────┼─────────────────┤
│ 1 │ 1ec940 │ 78.6053 │ 25.8932 │ 0 │

genie> hotel_matches[1, :code]
genie> "1ec940"

genie> hotel.code
genie> "1ec940"

genie> hotel_matches[1, :code] == hotel.code
genie> true

genie> hotel_matches[:code .== hotel.code, :]
genie> 0×4 DataFrames.DataFrame

```

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [May 22, 2018, 10:12am UTC](https://discourse.julialang.org/t/dataframe-element-wise-equality-filter/11070/2 "2018-05-22T10:12:55Z")

</div>

> [@essenciary](#):
>
> :code .== hotel.code

is an expression that will be eagerly evaluated. It is the same as writing

```julia
:code .== "1ec940"

```

which is just `false`. So what you are asking is:

```julia
hotel_matches[false, :]

```

You can look at e.g. [GitHub - JuliaData/DataFramesMeta.jl: Metaprogramming tools for DataFrames](https://github.com/JuliaStats/DataFramesMeta.jl#where) for dataframes queries (there are also a bunch of other packages that also does this).

---

<div class="post-metadata">

### Author: ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)
#### Post date: [May 22, 2018, 10:25am UTC](https://discourse.julialang.org/t/dataframe-element-wise-equality-filter/11070/3 "2018-05-22T10:25:31Z")

</div>

@kristoffer.carlsson  
Gotchya! What I was looking for then was:

```julia
genie> hotel_matches[hotel_matches[:code] .== hotel.code, :]
genie> 1×4 DataFrames.DataFrame
│ Row │ code │ address_relevance │ name_relevance │ stars_relevance │
├─────┼────────┼───────────────────┼────────────────┼─────────────────┤
│ 1 │ 1ec940 │ 78.6053 │ 25.8932 │ 0 │

```

Which does work as expected 🙂 Thanks!
