# Leftjoin with replacement

**URL:** <https://discourse.julialang.org/t/leftjoin-with-replacement/83457>\
**Category:** Data\
**Tags:** dataframes\
**Created:** [June 28, 2022, 12:48pm UTC](https://discourse.julialang.org/t/leftjoin-with-replacement/83457 "2022-06-28T12:48:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfaromartino](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alfaromartino/32/52986_2.png) [@alfaromartino](https://discourse.julialang.org/u/alfaromartino)\
**Post date:** [June 28, 2022, 12:48pm UTC](https://discourse.julialang.org/t/leftjoin-with-replacement/83457/1 "2022-06-28T12:48:24Z")

</div>

I thought of an option that seems a natural extension of `leftjoin`. Suppose that you have two dataframes, where one is a strict subset of the other.

```julia
df1 = DataFrame(ID=[1, 2, 3], Name=["John Doe", "Jane Doe", "Joe Blogs"], country=["US", "US", "US"])
3×3 DataFrame
 Row │ ID Name country 
     │ Int64 String String  
─────┼───────────────────────────
   1 │ 1 John Doe US
   2 │ 2 Jane Doe US
   3 │ 3 Joe Blogs US

df2 = DataFrame(ID=[2], Name=["Jane Doe"], country=["CA"])
1×3 DataFrame
 Row │ ID Name country 
     │ Int64 String String  
─────┼──────────────────────────
   1 │ 2 Jane Doe CA

```

Imagine you want to update the value of `df1.country` based on `df2`. It seems natural to have:  
`leftjoin!(df1, df2, on =[:ID,:Name]; replacement=true).` (or some other name, like `subset=true`), whose result would be

```julia
 Row │ ID Name country 
     │ Int64 String String  
─────┼───────────────────────────
   1 │ 1 John Doe US
   2 │ 2 Jane Doe CA
   3 │ 3 Joe Blogs US

```

I was thinking that this could be useful if you had `df1`, but after several months there are updates to information or corrections, and they are presented as in `df2`.

Best

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 28, 2022, 1:42pm UTC](https://discourse.julialang.org/t/leftjoin-with-replacement/83457/2 "2022-06-28T13:42:13Z")

</div>

See:

[https://github.com/JuliaData/DataFrames.jl/issues/2243](https://github.com/JuliaData/DataFrames.jl/issues/2243)

---

<div class="post-metadata">

**Author:** ![alfaromartino](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alfaromartino/32/52986_2.png) [@alfaromartino](https://discourse.julialang.org/u/alfaromartino)\
**Post date:** [June 28, 2022, 2:01pm UTC](https://discourse.julialang.org/t/leftjoin-with-replacement/83457/3 "2022-06-28T14:01:14Z")

</div>

I hadn’t seen that post, since I wasn’t thinking of missing values in particular. But, yeah, it’s exactly the same point. Nice to know that people are already thinking about it!

---

<div class="post-metadata">

**Author:** ![DataFrames](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@DataFrames](https://discourse.julialang.org/u/DataFrames)\
**Post date:** [July 23, 2022, 5:15am UTC](https://discourse.julialang.org/t/leftjoin-with-replacement/83457/4 "2022-07-23T05:15:46Z")

</div>

use `update` in `InMemoryDatasets`.
