Using findfirst with for multiple values and columns in a Dataframe?

The function has this fingerprint searchsortedfirst(a, x; by=<transform>, lt=<comparison>, rev=false).
The comparison between the value to be searched for x and the candidate values a_i is done in the following way lt(by(x),by(a_i)) until the first a_i >=x is found.
I’ll try to give some examples to clarify, in the end, Dan’s “slightly awkward” use of it (euphemism).

julia> searchsortedfirst(1:10,-3)
1

julia> searchsortedfirst(1:10,-3,by= abs)
3

julia> searchsortedfirst(1:10,0,by=a_i->(a_i==0 ? 3 : sqrt(a_i)))
9

How does this last case work?
You are required to find the first value in 1:10 that is >=0.
But the comparison is done by first transforming the values with by().
therefore the
first comparison lt( by(x), by(a_1)) is 3 <= sqrt(1);
the second comparison lt( by(x), by(a_1)) is 3 <= sqrt(2);

the ninth comparison lt( by(x), by(a_1)) is 3 <= sqrt(9); it’s the “good” one.

You might think that 0 is a particular value but it plays no specific role.
See the examples below:

julia> searchsortedfirst(1:10,NaN,by=x->(x===NaN ? 3 : sqrt(x)))
9

julia> searchsortedfirst(1:10,'x',by=x->(x=='x' ? 3 : sqrt(x)))
9

I add an alternative solution that could be useful if you have to do a lot of research.


gdf=groupby(df2,[:dates,:times]) 

d=Dict(zip(Tuple.(keys(gdf)),gdf.starts)) 

d[(Date(2024,2,23),Time(10,00,00))] 
2 Likes