# Array of heterogeneous named tuples to DataFrame

**URL:** <https://discourse.julialang.org/t/array-of-heterogeneous-named-tuples-to-dataframe/52339>\
**Category:** General Usage\
**Created:** [December 24, 2020, 8:00pm UTC](https://discourse.julialang.org/t/array-of-heterogeneous-named-tuples-to-dataframe/52339 "2020-12-24T20:00:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [December 24, 2020, 8:00pm UTC](https://discourse.julialang.org/t/array-of-heterogeneous-named-tuples-to-dataframe/52339/1 "2020-12-24T20:00:36Z")

</div>

Hi all-

I would like to convert an array of named tuples to a dataframe. This can be achieved with the `DataFrame` constructor when the named tuples have the same keys. However, in my case, the named tuples do not necessarily have the same keys. I would like to use `missing` in cases where one named tuple does not have a key that is in another named tuple. Here is a simple example:

`np = [(x=1,y=2,z=3),(x=2,y=10)]`

Desired Result:

```julia
 Row │ x y z       
     │ Int64 Int64 Int64?  
─────┼───────────────────────
   1 │ 1 2 3
   2 │ 2 10 missing 

```

Is there an easy way to do this? Thanks!

---

<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:** [December 24, 2020, 8:36pm UTC](https://discourse.julialang.org/t/array-of-heterogeneous-named-tuples-to-dataframe/52339/2 "2020-12-24T20:36:33Z")

</div>

Push to an empty data frame in a loop

```julia
df = DataFrame()
for n in np
    push!(df, n; cols = :union)
end

```

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [December 24, 2020, 8:45pm UTC](https://discourse.julialang.org/t/array-of-heterogeneous-named-tuples-to-dataframe/52339/3 "2020-12-24T20:45:18Z")

</div>

I figured there was a better way as my attempts became increasingly convoluted. I totally forgot about the :union option. Thank you!
