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

I tried


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

but neither worked.

using DataFrames
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};
1 Like