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