# How to fill dataframe from an array and date range?

**URL:** <https://discourse.julialang.org/t/how-to-fill-dataframe-from-an-array-and-date-range/28227>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [August 31, 2019, 1:45am UTC](https://discourse.julialang.org/t/how-to-fill-dataframe-from-an-array-and-date-range/28227 "2019-08-31T01:45:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![abeburnett](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abeburnett/32/8974_2.png) [@abeburnett](https://discourse.julialang.org/u/abeburnett)\
**Post date:** [August 31, 2019, 1:45am UTC](https://discourse.julialang.org/t/how-to-fill-dataframe-from-an-array-and-date-range/28227/1 "2019-08-31T01:45:38Z")

</div>

So let’s see if I can convey what I’m trying to do:

I have a list (array actually) of 931 technology names, and a known minimum date and maximum date. I want to create a dataframe in the most Julia-esque way which has every date (between the minimum and maximum dates) associated with every technology name, and missing for any additional columns I want in the dataframe. How do I do this?

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 31, 2019, 6:13am UTC](https://discourse.julialang.org/t/how-to-fill-dataframe-from-an-array-and-date-range/28227/2 "2019-08-31T06:13:24Z")

</div>

> [@abeburnett](#):
>
> which has every date (between the minimum and maximum dates) associated with every technology name, and missing for any additional columns I want in the dataframe.

Perhaps you need `join`, but I don’t fully understand what you are trying to do from this description. Perhaps provide a simplified example of an input and the expected output; or an MWE working code that you want to simplify.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [August 31, 2019, 12:47pm UTC](https://discourse.julialang.org/t/how-to-fill-dataframe-from-an-array-and-date-range/28227/3 "2019-08-31T12:47:51Z")

</div>

I’m also unsure of what you want - when you say “every date”, do you mean year, month, day? There are a number of ways I can imagine structuring the DataFrame, and I don’t think any of them after more or less Julian than others.

Once you explain the form your data takes (you said you have an array of technologies, but how are they situated with dates?), and more about the form you want it in, I think we can be of more help.  
In particular, if you can make a MWE as Tamas suggested, maybe just take two or three of the technologies and dates and manually build the DataFrame you want.

---

<div class="post-metadata">

**Author:** ![abeburnett](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abeburnett/32/8974_2.png) [@abeburnett](https://discourse.julialang.org/u/abeburnett)\
**Post date:** [September 3, 2019, 9:23pm UTC](https://discourse.julialang.org/t/how-to-fill-dataframe-from-an-array-and-date-range/28227/4 "2019-09-03T21:23:56Z")

</div>

Y’all gave me some ideas, so here’s what I came up with:

````julia
unique_reddit_dates = DataFrame(reddit_date = unique(comment_df.reddit_date))     
comment_df_empty = DataFrame(audience = reddit_search.audience, subdomain = reddit_search.subdomain, comment_count = 0)
comment_df_empty = join(comment_df_empty, unique_reddit_dates, kind = :cross, makeunique = true)
comment_df_empty[:subdomain_all_freq_comment_count] = 0

# then remove empty records which we have actual values for (roughly thirty thousand right now)
not_in_comment_df = join(comment_df_empty, comment_df, on = [:audience, :subdomain, :reddit_date], kind = :anti)

# and add in the blank records
comment_df = vcat(comment_df, not_in_comment_df)```

Which works. Is there a better/more Julia-ish way?
````

---

<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:** [September 3, 2019, 10:52pm UTC](https://discourse.julialang.org/t/how-to-fill-dataframe-from-an-array-and-date-range/28227/5 "2019-09-03T22:52:26Z")

</div>

I would create a function that takes mindate and maxdate and returns a vector of all of the days you’d want to include that fall between them.

Then I’d create a loop that loops over your existing list, calls this function, creates a DataFrame from the result, and sequentially append these DataFrames together.
