# DataFrames: how to convert many arrays into a data frame?

**URL:** <https://discourse.julialang.org/t/dataframes-how-to-convert-many-arrays-into-a-data-frame/73966>\
**Category:** General Usage\
**Tags:** dataframes, arrays\
**Created:** [January 3, 2022, 2:43pm UTC](https://discourse.julialang.org/t/dataframes-how-to-convert-many-arrays-into-a-data-frame/73966 "2022-01-03T14:43:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![VivMendes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vivmendes/32/16477_2.png) [@VivMendes](https://discourse.julialang.org/u/VivMendes)\
**Post date:** [January 3, 2022, 2:43pm UTC](https://discourse.julialang.org/t/dataframes-how-to-convert-many-arrays-into-a-data-frame/73966/1 "2022-01-03T14:43:30Z")

</div>

Suppose I ran different loops in a notebook. In each one, I obtain e,g., a `1×120 Matrix{Float64}` array. I want to collect some of them in a data frame. I know how to do it (please, see MWE below). However, I find my clumsy code both primate and inefficient. There must be a way to make it more appealing and efficient. Unfortunately, my limited knowledge of `DataFrames` precludes me from providing a solution to this problem. Some help would be very much appreciated. Thanks.

```julia
df1 = DataFrame(y1',[:a1])
df2 = DataFrame(k1',[:a2])
df3 = DataFrame(n1',[:a3])
df4 = DataFrame(time, [:t])
irfs = hcat(df4, df1, df2, df3) #, makeunique=true)

```

 ![aa](https://global.discourse-cdn.com/julialang/original/3X/5/a/5a18151ef456b84543a0666727103be4dcee9ea6.png)

---

<div class="post-metadata">

**Author:** ![L\_Adam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/l_adam/32/12086_2.png) [@L\_Adam](https://discourse.julialang.org/u/L_Adam)\
**Post date:** [January 3, 2022, 2:56pm UTC](https://discourse.julialang.org/t/dataframes-how-to-convert-many-arrays-into-a-data-frame/73966/2 "2022-01-03T14:56:41Z")

</div>

guess you could just perform cat first then transpose, haven’t tested yet

```julia
A = [t; a1; a2; a3]
C = [:t, :a1, :a2, :a3]

d = DataFrame(A', C)

```

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [January 3, 2022, 3:05pm UTC](https://discourse.julialang.org/t/dataframes-how-to-convert-many-arrays-into-a-data-frame/73966/3 "2022-01-03T15:05:14Z")

</div>

I would write

```julia
DataFrame(t=t, a1=vec(y1), a2=vec(k1), a3=vec(n1))

```

---

<div class="post-metadata">

**Author:** ![VivMendes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vivmendes/32/16477_2.png) [@VivMendes](https://discourse.julialang.org/u/VivMendes)\
**Post date:** [January 3, 2022, 3:29pm UTC](https://discourse.julialang.org/t/dataframes-how-to-convert-many-arrays-into-a-data-frame/73966/4 "2022-01-03T15:29:25Z")

</div>

@sijo, @L_Adam, thanks for helping. I have tested @sijo’s solution because it looks more straightforward and intuitive. It is simply amazing how good solutions are ridiculously simple … for those who know it. Thanks a lot.
