Functions mimic pandas apply(list)

Hi Guys,
I wanna ask about the expression that could mimic python’s df.groupby("a").apply(list)
And here is what the function do:

ds = DataFrame(a=repeat([1,2],inner=2),b='a':'j')

and result should be

a b
1 [‘a’,‘b’,‘c’,‘d’,‘e’]
2 [‘f’,‘g’,‘h’,‘i’,‘j’]

Thanks guys!

if you want to avoid copying data:

julia> combine(groupby(ds, :a), :b => Ref => :b)
2×2 DataFrame
 Row │ a      b
     │ Int64  SubArray…
─────┼──────────────────────────────────
   1 │     1  ['a', 'b', 'c', 'd', 'e']
   2 │     2  ['f', 'g', 'h', 'i', 'j']

and if you wan to copy:

julia> combine(groupby(ds, :a), :b => Ref∘copy => :b)
2×2 DataFrame
 Row │ a      b
     │ Int64  Array…
─────┼──────────────────────────────────
   1 │     1  ['a', 'b', 'c', 'd', 'e']
   2 │     2  ['f', 'g', 'h', 'i', 'j']
1 Like