DataFrames.jl icon indicating copy to clipboard operation
DataFrames.jl copied to clipboard

Allow unstack to take multiple columns to unstack on

Open bkamins opened this issue 4 years ago • 2 comments

See https://github.com/invenia/Wrangling.jl/issues/10.

This should be worked on after #2147 is merged.

bkamins avatar Mar 09 '20 16:03 bkamins

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)

bkamins avatar Mar 09 '20 20:03 bkamins

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

bkamins avatar Feb 28 '22 11:02 bkamins

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)

bkamins avatar Dec 05 '22 11:12 bkamins