Hello, I’m trying to figure out how to create a 0,1 valued column in a dataframe based on comparing a dataframe column with a list. Here is an example
data = DataFrame(:index => String, :values => Int64)
push!(data, ["a", 1])
push!(data, ["b", 2])
push!(data, ["c", 1])
list = ["a","b"]
I’m trying to create a column called PASS which is 0,1 based on if the index column in this df contains one of the values in this list.
I’ve tried this, but this doesn’t seem to work
data.pass .= data[in.(data.index , list), :]
Any help with this?
Is this what you are looking for?
julia> data.pass = map(in(list), data.index)
list is small use
transform!(data, :index => ByRow(in(list)) => :pass)
if it is large use
transform!(data, :index => ByRow(in(Set(list))) => :pass)
Thanks, this works! I guess it would be nice if there were a simple broadcast of the IN statement like in.(list) but I can use this. thanks.
the new column can be built like this
data.pass = in.(data.index , [list])
data.repass= data.index .∈ [list]