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

**URL:** <https://discourse.julialang.org/t/using-findfirst-with-for-multiple-values-and-columns-in-a-dataframe/111953>\
**Category:** New to Julia\
**Tags:** dataframes\
**Created:** [March 21, 2024, 9:35pm UTC](https://discourse.julialang.org/t/using-findfirst-with-for-multiple-values-and-columns-in-a-dataframe/111953 "2024-03-21T21:35:56Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [March 23, 2024, 8:29pm UTC](https://discourse.julialang.org/t/using-findfirst-with-for-multiple-values-and-columns-in-a-dataframe/111953/16 "2024-03-23T20:29:12Z")

</div>

> [@phantom](#):
>
> Any clarification would be much appreciated thanks!

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
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
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.

```julia

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

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

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

```

---

_[View the full topic](https://discourse.julialang.org/t/using-findfirst-with-for-multiple-values-and-columns-in-a-dataframe/111953)._
