Store array in cells of DataFrame?

I’m having trouble with the following behavior:

julia> df = DataFrame(a = Array[], b = Int[]); push!(df, [[1,2,3], 6])
1×2 DataFrame
│ Row │ a         │ b     │
│     │ Array     │ Int64 │
├─────┼───────────┼───────┤
│ 1   │ [1, 2, 3] │ 6     │

but then:

julia> df = Dict("a" => [1,2,3], "b" => 6) |> DataFrame
3×2 DataFrame
│ Row │ a     │ b     │
│     │ Int64 │ Int64 │
├─────┼───────┼───────┤
│ 1   │ 1     │ 6     │
│ 2   │ 2     │ 6     │
│ 3   │ 3     │ 6     │

how to make the second one work like the first?

It’s getting confused about what shapes you are trying to broadcast to, because the columns have different sizes (3 and 0). You should think of the Dict as the dataframe itself, that is a dict of columns.

This works

DataFrame(Dict("a"=>[[1,2,3]], "b"=>[6]))
1 Like

ah… a classic [[]], should have though about this.