Multiple condition findall in dataframes

I am trying to use findall to find index of items in a dataframe based on multiple conditions. In the example below, I want to find indices when value in FIELD1 = A and values in FIELD3 = 0

df = DataFrame(ID = collect(1:5), FIELD1 = ["A","B","A","C","A"], FIELD3 = [0,1,0,1,1],FIELD4 = ["One","Two","Three","Four","One"])
# with one condition I can find indices using
findall(x -> x == "A", df.FIELD1)
# with two conditions, I don't know the correct syntax 
findall((x -> (x == "A" && x == 0), (df.FIELD1,  df.FIELD3)))

Any ideas?

Probably map would be simplest.

julia> map(df.FIELD1, df.FIELD3) do a, b
           a == "A" && b == 0
5-element Vector{Bool}:

Thanks. This does not return the indices or row numbers that I am after. I would like to collect row numbers as shown in my code based on one condition

Oh sorry. Call findall on the result, I suppose. Maybe someone else can chime in with a better solution.

julia> findall([false, false, true])
1-element Vector{Int64}:

It depends on what you call better but one can do:

[i for (i, (a,b)) in enumerate(zip(df.FIELD1, df.FIELD3)) if a == "A" && b == 0]

Thank you

1 Like