Questions about filter and broadcast

For DataFrames you can pass a Pair as the first argument with a column name and a function to apply rowwise to that column.

Your main issue though has nothing to do with DataFrames but with the simple fact that

julia> 2 == [2, 3]
false

You are looking for containment, i.e. in:

julia> filter(:x => in([2, 3]), df)
2×2 DataFrame
 Row │ x      y
     │ Int64  String
─────┼───────────────
   1 │     3  b
   2 │     2  a

P.S. to make what you tried originally work more directly you could have checked whether the value was equal to 2 or to 3:

julia> filter(:x => row -> row==2||row==3, df)
2×2 DataFrame
 Row │ x      y
     │ Int64  String
─────┼───────────────
   1 │     3  b
   2 │     2  a

But that’s a bit cumbersome especially for larger collections.

1 Like