How to convert an array to a dataframe?

column = rand(Int64, 10)
DataFrame(column,  [:col1])

This gives:

ERROR: ArgumentError: columns argument must be a vector of AbstractVector objects
1 Like

From the docs:

using DataFrames
df = DataFrame(A = 1:4, B = ["M", "F", "F", "M"])

In your case,

column = rand(Int64, 10)
df = DataFrame(col1 = column)

Note that when initializing, you don’t need to use symbols.

1 Like

You almost had it - the error is telling you that the first argument needs to be a vector of vectors, rather than a vector:

julia> using DataFrames

julia> column = rand(5);

julia> DataFrame([column], [:col1]) # Note the enclosing [] around column!
5Γ—1 DataFrame
β”‚ Row β”‚ col1      β”‚
β”‚     β”‚ Float64   β”‚
β”œβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1   β”‚ 0.487455  β”‚
β”‚ 2   β”‚ 0.439289  β”‚
β”‚ 3   β”‚ 0.496783  β”‚
β”‚ 4   β”‚ 0.0520202 β”‚
β”‚ 5   β”‚ 0.661149  β”‚