# Assembling data using DataFrame such that rows where a particular array has empty elements are discounted

**URL:** <https://discourse.julialang.org/t/assembling-data-using-dataframe-such-that-rows-where-a-particular-array-has-empty-elements-are-discounted/42946>\
**Category:** New to Julia\
**Created:** [July 12, 2020, 1:54pm UTC](https://discourse.julialang.org/t/assembling-data-using-dataframe-such-that-rows-where-a-particular-array-has-empty-elements-are-discounted/42946 "2020-07-12T13:54:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)\
**Post date:** [July 12, 2020, 1:54pm UTC](https://discourse.julialang.org/t/assembling-data-using-dataframe-such-that-rows-where-a-particular-array-has-empty-elements-are-discounted/42946/1 "2020-07-12T13:54:41Z")

</div>

I am collecting arrays of data using DataFrames:

```
df = DataFrame(marketIds = x[:,1], stockIds = x[:,2], price = x[:,3])

```

In the array of prices, some elements are empty. How do I assemble df such that rows where price is empty are not included?

---

<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:** [July 12, 2020, 2:04pm UTC](https://discourse.julialang.org/t/assembling-data-using-dataframe-such-that-rows-where-a-particular-array-has-empty-elements-are-discounted/42946/2 "2020-07-12T14:04:01Z")

</div>

Being lazy, I would just use `missing` to encode the “empty” elements, and then `dropmissing`.

---

<div class="post-metadata">

**Author:** ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)\
**Post date:** [July 12, 2020, 2:13pm UTC](https://discourse.julialang.org/t/assembling-data-using-dataframe-such-that-rows-where-a-particular-array-has-empty-elements-are-discounted/42946/3 "2020-07-12T14:13:21Z")

</div>

I think that is a good solution, but I have a new question. How do I take an array with empty elements and replace these with missing?

---

<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:** [July 12, 2020, 2:17pm UTC](https://discourse.julialang.org/t/assembling-data-using-dataframe-such-that-rows-where-a-particular-array-has-empty-elements-are-discounted/42946/4 "2020-07-12T14:17:29Z")

</div>

What do you mean by “empty”? can show a subset of your matrix as an example?

---

<div class="post-metadata">

**Author:** ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)\
**Post date:** [July 12, 2020, 2:27pm UTC](https://discourse.julialang.org/t/assembling-data-using-dataframe-such-that-rows-where-a-particular-array-has-empty-elements-are-discounted/42946/5 "2020-07-12T14:27:44Z")

</div>

typeof(price) Vector{Any}

2.20  
4.00  
3.90  
1.74  
4.50  
3.70  
1.93  
2.46  
3.45  
“”  
“”  
2.08

So, the “empty” are actually " "

---

<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:** [July 12, 2020, 2:33pm UTC](https://discourse.julialang.org/t/assembling-data-using-dataframe-such-that-rows-where-a-particular-array-has-empty-elements-are-discounted/42946/6 "2020-07-12T14:33:00Z")

</div>

Okay my advice is two-fold.

1. Use

```julia
t = replace(x, "" => missing)
t = identity.(t)

```

to replace your empty strings with `missing`s.

1. Re-think the way you are importing data. You should really be having `Array{Union{Float64, Missing}}` from the start instead of `Array{Any}`. That will make your code a lot easier to work with. But I’m not sure how to help specifically without knowing how you are importing your data.
