I would like to destructure a DataFrame with NamedTuples into separate columns, using the keys as column names. For a similar problem with an array, I used something like transform!(df, :col => :identity => new_names). Is there a way I can take this:
2×2 DataFrame
Row │ x y
│ Float64 NamedTup…
─────┼──────────────────────────
1 │ 0.222043 (a = 1, b = 2)
2 │ 0.72646 (a = 3, b = 5)
and obtain this:
2×4 DataFrame
Row │ x y a b
│ Float64 NamedTup… Int64 Int64
─────┼────────────────────────────────────────
1 │ 0.222043 (a = 1, b = 2) 1 2
2 │ 0.72646 (a = 3, b = 5) 3 5
Thanks!
MWE
using DataFrames
df = DataFrame(x = rand(2), y =[(a=1,b=2),(a=3,b=5)])
df_new = DataFrame(x = df.x, y = df.y, a = [1,3], b = [2,5])