sorry if this obvious, fairly new to Julia. I think there must be a simple way to combine a single col from all DF groups into a single DF. I have this:
The way unstacking works is you specify row labels, column labels and values, unstack(df, :rows, :columns, :values), and you get a table with the values at the corresponding positions. In our case, we need to add the target rows from the position within each group (which is what eachindex => :row does), the target columns are from :dtype, and the values from :val.
Rows and columns are ordered by appearance
The column names in :target_column appear in the table in order of appearance, and similarly for :target_rows. I.e., :target_rows does not specify the row index — in fact, we can use any value for the row label:
julia> using DataFramesMeta
julia> @chain(gd,
@combine(:val, :row = 'v' .+ eachindex(:val)),
unstack(:row, :dtype, :val)
)
4×4 DataFrame
Row │ row AA BB CC
│ Char Int64? Int64? Int64?
─────┼──────────────────────────────
1 │ w 1 5 9
2 │ x 2 6 10
3 │ y 3 7 11
4 │ z 4 8 12
if the ultimate goal is to apply an aggregation function to the values of the various groups, you can avoid going through groupby and / or flatten in the following way