DataFrame element-wise equality filter

dataframes

#1

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):

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

#2

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

:code .== "1ec940"

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

hotel_matches[false, :]

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


#3

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

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 :slight_smile: Thanks!