# How to convert a NTuple of arrays to a DataFarame?

**URL:** https://discourse.julialang.org/t/how-to-convert-a-ntuple-of-arrays-to-a-datafarame/8985
**Category:** New to Julia
**Tags:** tuple, dataframes
**Created:** [February 11, 2018, 3:22am UTC](https://discourse.julialang.org/t/how-to-convert-a-ntuple-of-arrays-to-a-datafarame/8985 "2018-02-11T03:22:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [February 11, 2018, 3:22am UTC](https://discourse.julialang.org/t/how-to-convert-a-ntuple-of-arrays-to-a-datafarame/8985/1 "2018-02-11T03:22:51Z")

</div>

I have a tuple `tp = tuple([randstring(8) for i=1:5], rand(5)]`. Now it’s a tuple of arrays of the same length. How do I convert it to a DataFrame in the case where there are the number of arrays in the tuple is not known before hand?

```julia
function ntuple2dataframe(tp::NTuple)
  # what goes here
end

```

I tried

```julia
DataFrame(tp)

DataFrame(;Dict(i=>tp1 for (i,tp1) in enumerate(tp)))

```

but neither worked.

---

<div class="post-metadata">

### Author: ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)
#### Post date: [February 11, 2018, 5:11am UTC](https://discourse.julialang.org/t/how-to-convert-a-ntuple-of-arrays-to-a-datafarame/8985/2 "2018-02-11T05:11:49Z")

</div>

```julia
using DataFrames
srand(0)
tp = tuple([randstring(8) for i=1:5], rand(5))
df = DataFrame(collect(tp), [:A, :B])

```

You can inspect the relevant constructor at [here (line 132)](https://github.com/JuliaData/DataFrames.jl/commit/0fac3be3de3d95ef6ce8b422e0b7b6e672700f68).

```julia
function DataFrame(columns::AbstractVector, cnames::AbstractVector{Symbol};
                    makeunique::Bool=false)::DataFrame
    ...

```
