# Differences in Two DataFrames

**URL:** <https://discourse.julialang.org/t/differences-in-two-dataframes/90068>\
**Category:** General Usage\
**Tags:** dataframes\
**Created:** [November 10, 2022, 7:49pm UTC](https://discourse.julialang.org/t/differences-in-two-dataframes/90068 "2022-11-10T19:49:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![r0b0ty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/r0b0ty/32/27250_2.png) [@r0b0ty](https://discourse.julialang.org/u/r0b0ty)\
**Post date:** [November 10, 2022, 7:49pm UTC](https://discourse.julialang.org/t/differences-in-two-dataframes/90068/1 "2022-11-10T19:49:12Z")

</div>

Given two DataFrames of different lengths, and different parameter names…

```julia
julia> dfA = DataFrame(:Parameter => ["size", "weight", "color", "smell"],
       :Value => ["small", "120", "red", "none"])
4×2 DataFrame
 Row │ Parameter Value  
     │ String String 
─────┼───────────────────
   1 │ size small
   2 │ weight 120
   3 │ color red
   4 │ smell none

```

```julia
julia> dfB = DataFrame(:Parameter => ["size", "color", "smell", "temperature", "price"],
       :Value => ["small", "blue", "none", "hot", "50"])
5×2 DataFrame
 Row │ Parameter Value  
     │ String String 
─────┼─────────────────────
   1 │ size small
   2 │ color blue
   3 │ smell none
   4 │ temperature hot
   5 │ price 50

```

I’d like a resulting DataFrame containing only the rows with non-matching _ **Values** _, from **dfB** ’s perspective. So in this example, “_ **weight** _” is not in **dfB** , so it should be ignored, but “_ **temperature** _” and “_ **price** _” are new parameters, so they should register as a difference. The expectation, in this example is a DataFrame like this:

```julia
 Row │ Parameter Value  
     │ String String 
─────┼─────────────────────
   1 │ color blue
   2 │ temperature hot
   3 │ price 50

```

I’m experimenting with the `filter()` function, but haven’t made it work. I’m pretty sure I can do this using a `for()` loop, but I’d like to avoid that if possible. Any suggestions? **Thanks in advance!**

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 10, 2022, 7:54pm UTC](https://discourse.julialang.org/t/differences-in-two-dataframes/90068/2 "2022-11-10T19:54:38Z")

</div>

I don’t think such a thing exists. See an [earlier thread](https://discourse.julialang.org/t/is-there-a-package-to-do-dataframes-comparisons/65713/5).

---

<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:** [November 10, 2022, 8:10pm UTC](https://discourse.julialang.org/t/differences-in-two-dataframes/90068/3 "2022-11-10T20:10:47Z")

</div>

try this

```julia
antijoin(dfB,dfA,on=[:Parameter, :Value])

```

---

<div class="post-metadata">

**Author:** ![r0b0ty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/r0b0ty/32/27250_2.png) [@r0b0ty](https://discourse.julialang.org/u/r0b0ty)\
**Post date:** [November 10, 2022, 8:35pm UTC](https://discourse.julialang.org/t/differences-in-two-dataframes/90068/4 "2022-11-10T20:35:51Z")

</div>

`antijoin()` certainly works on this sample data set, thanks! I’ll try it with the real data, but I don’t see why it would fail. I’ll report back, thanks, again!

**EDIT** : As expected, it works perfectly. I wasn’t familiar with the function, so thank you, @rocco_sprmnt21.

---

<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:** [November 10, 2022, 10:57pm UTC](https://discourse.julialang.org/t/differences-in-two-dataframes/90068/5 "2022-11-10T22:57:26Z")

</div>

Some variants and alternatives

```julia
antijoin(dfB,dfA,on=names(dfB))
DataFrame(setdiff(eachrow(dfB),eachrow(dfA)))
DataFrame([x for x in eachrow(dfB) if x ∉ eachrow(dfA)])
eachrow(dfB)[findall(x->x ∉ eachrow(dfA), eachrow(dfB))]  

```

```julia
dfB[findall(x->x ∉ eachrow(dfA), eachrow(dfB)),:] 

```

---

<div class="post-metadata">

**Author:** ![r0b0ty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/r0b0ty/32/27250_2.png) [@r0b0ty](https://discourse.julialang.org/u/r0b0ty)\
**Post date:** [November 11, 2022, 2:34pm UTC](https://discourse.julialang.org/t/differences-in-two-dataframes/90068/6 "2022-11-11T14:34:21Z")

</div>

This is very good info, which I’m sure I’ll reference in the future. Thanks again! My attempt with setdiff() had failed when I tried it, but now see that the use of eachrow() is key. I’ll play with these options to get more familiar with their use and syntax.
