# Merging dataframes on dates

**URL:** https://discourse.julialang.org/t/merging-dataframes-on-dates/72417
**Category:** General Usage
**Tags:** question
**Created:** [December 1, 2021, 10:57pm UTC](https://discourse.julialang.org/t/merging-dataframes-on-dates/72417 "2021-12-01T22:57:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Bruno322](https://avatars.discourse-cdn.com/v4/letter/b/8dc957/32.png) [@Bruno322](https://discourse.julialang.org/u/Bruno322)
#### Post date: [December 1, 2021, 10:57pm UTC](https://discourse.julialang.org/t/merging-dataframes-on-dates/72417/1 "2021-12-01T22:57:16Z")

</div>

I’m trying to clean a data set and I am stuck at the last step.

The main dataframe, that I call **maindf** , will contain all the data and has 3000 rows and 200 columns, like this

 ![Capture](https://global.discourse-cdn.com/julialang/original/3X/0/8/08383dc96d0451a2b6cecdba7c15992610d5fc62.png)  
Each row of maindf will be filled with a time series.

Each time series, called **tempdf** , is a data frame with one row:  
 ![Capture2](https://global.discourse-cdn.com/julialang/original/3X/1/a/1abbbd1fe0d0182eef8bf93813b3eff798961cfe.png)  
I would like that each observation in tempdf automatically goes into the proper part of maindf. I would then iterate by sending the first time series in the first row of maindf etc.  
The problem is that each series has a different number of observations, and there may be holes in the dates, so I do not know how to match them properly.

The data set is small so I am more interested in a simple solution than an efficient one. I tried all my knowledge of dataframes and joins but this is beyond 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: [December 1, 2021, 11:01pm UTC](https://discourse.julialang.org/t/merging-dataframes-on-dates/72417/2 "2021-12-01T23:01:46Z")

</div>

Would definitely suggest you do things the opposite way that you are now. Time series almost always works best as a column vector.

In this case I’d create individual dataframes for each series, then use something like leftjoin on date (perhaps outerjoin or rightjoin instead). You could first compute the union of all date columns to get the complete set of dates and use that as your base dataframe to initialize the join.

---

<div class="post-metadata">

### Author: ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)
#### Post date: [December 1, 2021, 11:19pm UTC](https://discourse.julialang.org/t/merging-dataframes-on-dates/72417/3 "2021-12-01T23:19:42Z")

</div>

> [@tbeason](#):
>
> Would definitely suggest you do things the opposite way that you are now. Time series almost always works best as a column vector.

+1 on this. `stack` and `vcat`.

---

<div class="post-metadata">

### Author: ![Bruno322](https://avatars.discourse-cdn.com/v4/letter/b/8dc957/32.png) [@Bruno322](https://discourse.julialang.org/u/Bruno322)
#### Post date: [December 1, 2021, 11:29pm UTC](https://discourse.julialang.org/t/merging-dataframes-on-dates/72417/4 "2021-12-01T23:29:25Z")

</div>

Worked perfectly. Instead of creating an empty dataframe, I just created a dataframe column with the dates and added all the time series looping leftjoin. Easy solutions are always the best. Thank you very much.  
(I think this is a record, 5 minutes from answer to exact question.)
