How would I pass in a boolean condition to index a Julia Dataframe

Hi how’s it going?

Say I set a variable X = Symbol(“column1”).==“Yes”

How would I pass that variable in to index just like I would if I passed the actual statement in:

data[data[Symbol("column1)].==“Yes”, :]

If all you are trying to do is to subset the data the easier way would be to use something like @where from DataFramesMeta.jl.

@where(data,:column1 .== "Yes")

That doesn’t play nicely with Symbol though, and may not always work for your usecase, so you can do

X = data[!,Symbol("column1")] .== "Yes"
subset = data[X,:]
3 Likes

Ok cool thank you!