# Is there a faster way to extract single rows of a dataframe than the filter function

**URL:** <https://discourse.julialang.org/t/is-there-a-faster-way-to-extract-single-rows-of-a-dataframe-than-the-filter-function/34821>\
**Category:** General Usage\
**Created:** [February 18, 2020, 5:53pm UTC](https://discourse.julialang.org/t/is-there-a-faster-way-to-extract-single-rows-of-a-dataframe-than-the-filter-function/34821 "2020-02-18T17:53:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julia1](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Julia1](https://discourse.julialang.org/u/Julia1)\
**Post date:** [February 18, 2020, 5:53pm UTC](https://discourse.julialang.org/t/is-there-a-faster-way-to-extract-single-rows-of-a-dataframe-than-the-filter-function/34821/1 "2020-02-18T17:53:11Z")

</div>

Hi how’s it going, here is the code I’m currently using:

df is a 1 row dataframe.  
df2 is a multiple row dataframe

x= filter(row → row[Symbol(‘ID’)][1]==df[Symbol(“ID”)][1], df2])

So essentially I’m trying to do a lookup and find rows in df2 where the row is equal to the “ID” column in df. df is just a one row dataframe.

I’m new to Julia and I know this is probably incredibly inefficient, using 1 row dataframes and what not. Can someone help me?

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [February 18, 2020, 6:07pm UTC](https://discourse.julialang.org/t/is-there-a-faster-way-to-extract-single-rows-of-a-dataframe-than-the-filter-function/34821/2 "2020-02-18T18:07:45Z")

</div>

```julia
x = df2[!,:ID] .== df[1,:ID] 
df2[x,:]

```

---

<div class="post-metadata">

**Author:** ![zweiglimmergneis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zweiglimmergneis/32/7892_2.png) [@zweiglimmergneis](https://discourse.julialang.org/u/zweiglimmergneis)\
**Post date:** [February 18, 2020, 8:58pm UTC](https://discourse.julialang.org/t/is-there-a-faster-way-to-extract-single-rows-of-a-dataframe-than-the-filter-function/34821/3 "2020-02-18T20:58:22Z")

</div>

A bit more verbose than tbeason’s solution

```julia
using Query
res = @from i in df2 begin
@where i.ID == df1[1, :ID]
@select i
@collect DataFrame
end

```

---

<div class="post-metadata">

**Author:** ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Post date:** [February 18, 2020, 9:50pm UTC](https://discourse.julialang.org/t/is-there-a-faster-way-to-extract-single-rows-of-a-dataframe-than-the-filter-function/34821/4 "2020-02-18T21:50:02Z")

</div>

You should definitely use joins: [Joins · DataFrames.jl](http://juliadata.github.io/DataFrames.jl/stable/man/joins/)
