# I have an array of 31 arrays and would like to make it a DataFrame. Need some help

**URL:** <https://discourse.julialang.org/t/i-have-an-array-of-31-arrays-and-would-like-to-make-it-a-dataframe-need-some-help/37130>\
**Category:** General Usage\
**Created:** [April 6, 2020, 10:04pm UTC](https://discourse.julialang.org/t/i-have-an-array-of-31-arrays-and-would-like-to-make-it-a-dataframe-need-some-help/37130 "2020-04-06T22:04:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julia1](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Julia1](https://discourse.julialang.org/u/Julia1)\
**Post date:** [April 6, 2020, 10:04pm UTC](https://discourse.julialang.org/t/i-have-an-array-of-31-arrays-and-would-like-to-make-it-a-dataframe-need-some-help/37130/1 "2020-04-06T22:04:31Z")

</div>

Hi how’s it going,

I have an array of 31 arrays, each with 3 items in it. first two items are strings, third is a float. I just want to transform this into a Julia DataFrame and export to CSV. Just calling the DataFrame method gave me a 1 column dataframe with the entire row as one column. Can someone help me with this?

Any help would be greatly appreciated!

Thanks.

---

<div class="post-metadata">

**Author:** ![bashonubuntu](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@bashonubuntu](https://discourse.julialang.org/u/bashonubuntu)\
**Post date:** [April 6, 2020, 10:05pm UTC](https://discourse.julialang.org/t/i-have-an-array-of-31-arrays-and-would-like-to-make-it-a-dataframe-need-some-help/37130/2 "2020-04-06T22:05:17Z")

</div>

Can you post your array?

---

<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:** [April 6, 2020, 10:12pm UTC](https://discourse.julialang.org/t/i-have-an-array-of-31-arrays-and-would-like-to-make-it-a-dataframe-need-some-help/37130/3 "2020-04-06T22:12:49Z")

</div>

```julia
df = DataFrame()
for i in 1:length(array_of_vectors)
    df[:, Symbol(:x, i)] = array_of_vectors[i]
end

```

---

<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:** [April 6, 2020, 10:15pm UTC](https://discourse.julialang.org/t/i-have-an-array-of-31-arrays-and-would-like-to-make-it-a-dataframe-need-some-help/37130/4 "2020-04-06T22:15:49Z")

</div>

Can you post the results of `Pkg.status()`?

I am on master and have

```julia
julia> DataFrame([rand(3) for i in 1:31]) 
3×31 DataFrame. Omitted printing of 25 columns
│ Row │ x1 │ x2 │ x3 │ x4 │ x5 │ x6 │
│ │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │
├─────┼───────────┼──────────┼───────────┼──────────┼──────────┼──────────┤
│ 1 │ 0.74393 │ 0.099329 │ 0.394221 │ 0.927078 │ 0.609199 │ 0.929626 │
│ 2 │ 0.850305 │ 0.597505 │ 0.441102 │ 0.37355 │ 0.432169 │ 0.312555 │
│ 3 │ 0.0256715 │ 0.818313 │ 0.0370936 │ 0.763612 │ 0.791267 │ 0.209623 │

```

---

<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:** [April 6, 2020, 10:21pm UTC](https://discourse.julialang.org/t/i-have-an-array-of-31-arrays-and-would-like-to-make-it-a-dataframe-need-some-help/37130/5 "2020-04-06T22:21:17Z")

</div>

Alternatively, you can do

```julia
df = DataFrame(col1 = String[], col2 = String[], col3 = Float64[])
for v in array_of_vectors
    push!(df, v)
end

```

The reason this is a bit awkward is that it’s recommended that you store your “rows”- so to speak, as named tuples rather than vectors. If you store them as named tuples you can just do

```julia
df = DataFrame()
for v in arra_of_named_tuples
    push!(df, v)
end

```

EDIT: furthermore, if you have an array of named tuples you can just call

```julia
DataFrame(vector_of_named_tuples)

```

and it will work thanks to Tables.jl
