What is the proper way to specify a column by a string variable containing the column name in a DataFramesMeta query? I tried Symbol(var) but got an error.
julia> df = DataFrame(num = 1:3)
3×1 DataFrame
│ Row │ num │
│ │ Int64 │
├─────┼───────┤
│ 1 │ 1 │
│ 2 │ 2 │
│ 3 │ 3 │
Specifying the column using the colon notation works.
julia> @where(df, :num .== 2)
1×1 DataFrame
│ Row │ num │
│ │ Int64 │
├─────┼───────┤
│ 1 │ 2 │
But using Symbol(var) in place of the colon notation does not work. Is this an expected behavior?
julia> colname = "num"
"num"
julia> @where(df, Symbol(colname) .== 2)
ERROR: ArgumentError: invalid row index of type Bool
Stacktrace:
[1] DataFrameRow at /Users/nishina/.julia/packages/DataFrames/S3ZFo/src/dataframerow/dataframerow.jl:59 [inlined
]
[2] getindex(::DataFrame, ::Bool, ::Colon) at /Users/nishina/.julia/packages/DataFrames/S3ZFo/src/dataframerow/d
ataframerow.jl:92
[3] where(::DataFrame, ::var"#92#93") at /Users/nishina/.julia/packages/DataFramesMeta/c88dH/src/DataFramesMeta.
jl:186
[4] top-level scope at REPL[50]:1
julia> Symbol(colname) == :num
true