How to convert a NTuple of arrays to a DataFarame?

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?

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

I tried

DataFrame(tp)

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

but neither worked.

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).

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