DataFrames.jl
DataFrames.jl copied to clipboard
Allow unstack to take multiple columns to unstack on
See https://github.com/invenia/Wrangling.jl/issues/10.
This should be worked on after #2147 is merged.
Some implementation notes to take into acount:
- this will be tricky if we unstack
SubDataFrame
- this will be tricky if some or all values in the columns are
missing
(we need to decide how to handle this)
The question is if we need this functionality or the following is just enough:
julia> df = DataFrame(row=[1,1,1,1,2,2,2,2], col1=[1,1,2,2,1,1,2,2], col2=[1,2,1,2,1,2,1,2], values=1:8)
8×4 DataFrame
Row │ row col1 col2 values
│ Int64 Int64 Int64 Int64
─────┼─────────────────────────────
1 │ 1 1 1 1
2 │ 1 1 2 2
3 │ 1 2 1 3
4 │ 1 2 2 4
5 │ 2 1 1 5
6 │ 2 1 2 6
7 │ 2 2 1 7
8 │ 2 2 2 8
julia> unstack(select(df, :row, [:col1, :col2] => ByRow((x,y) -> string(x, "_", y)) => :col, :values), :row, :col, :values)
2×5 DataFrame
Row │ row 1_1 1_2 2_1 2_2
│ Int64 Int64? Int64? Int64? Int64?
─────┼───────────────────────────────────────
1 │ 1 1 2 3 4
2 │ 2 5 6 7 8
I am closing this in favor of https://github.com/JuliaData/DataFrames.jl/issues/3237 (to have a single place to discuss all related issues)