Best practice for the conversion from a vector of dictionaries to a dataframe

I’d like to know whether there is a convenient way of converting from a vector of dictionaries to a dataframe. For example,

julia> my_dict = Dict("a" => [1, 2, 3], "b" => [4])
my_dictDict{String, Vector{Int64}} with 2 entries:
  "b" => [4]
  "a" => [1, 2, 3]

julia> my_dict_list = DrWatson.dict_list(my_dict)
3-element Vector{Dict{String, Int64}}:
 Dict("b" => 4, "a" => 1)
 Dict("b" => 4, "a" => 2)
 Dict("b" => 4, "a" => 3)

julia> df = DataFrame(my_dict_list)  # something like this...?

I found the answer based on this post.

julia> vcat(DataFrame.(my_dict_list)...)
3Ɨ2 DataFrame
 Row │ a      b
     │ Int64  Int64
─────┼──────────────
   1 │     1      4
   2 │     2      4
   3 │     3      4

1 Like