Filtering DataFrame on variable attribute type

Hi, i have a simple DataFrame and want to extract rows that match certain values ​​for some (not necessarily all) attributes. Starting from here,

res = @from i in df begin
@where i.A = "a1"
@select i
@collect DataFrame
end

and having a vector

attribute_value::Vector{Symbol,Any}

I want to filter the dataframe based on the values ​​of each individual attribute in attribute_value.
I can’ t do something like this

@where i.A = "a1" && i.B = "b3" && ...

but with the faculty of changing the clauses at each iteration based on the pairs contained in attribute_value. I tried several way but can t find a solution.

DataFramesMeta.jl might be a solution here, if I understand your problem correctly.

@chain df begin
    @rsubset :A == "a1" && :B == "b3"
end

but with the faculty of changing the clauses at each iteration based on the pairs contained in attribute_value. I tried several way but can t find a solution.

I’m not sure what you mean, but you could pass a function that takes in a NamedTuple

julia> df = DataFrame(A = ["a1", "a2"], B = ["b3", "b4"]);

julia> function select_base_on_names(nt) 
           nms = propertynames(nt)    
           if nms == (:A, :B)
               nt.A == "a1" && nt.B == "b3"
           elseif nms == (:A,)
               true # accept everything
           end
       end;

julia> @rsubset df select_base_on_names(AsTable([:A]))
2×2 DataFrame
 Row │ A       B      
     │ String  String 
─────┼────────────────
   1 │ a1      b3
   2 │ a2      b4

julia> @rsubset df select_base_on_names(AsTable([:A, :B]))
1×2 DataFrame
 Row │ A       B      
     │ String  String 
─────┼────────────────
   1 │ a1      b3
1 Like