# Functions mimic pandas apply(list)

**URL:** <https://discourse.julialang.org/t/functions-mimic-pandas-apply-list/77813>\
**Category:** Data\
**Created:** [March 13, 2022, 5:53am UTC](https://discourse.julialang.org/t/functions-mimic-pandas-apply-list/77813 "2022-03-13T05:53:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frankiewaang](https://avatars.discourse-cdn.com/v4/letter/f/f9ae1b/32.png) [@Frankiewaang](https://discourse.julialang.org/u/Frankiewaang)\
**Post date:** [March 13, 2022, 5:53am UTC](https://discourse.julialang.org/t/functions-mimic-pandas-apply-list/77813/1 "2022-03-13T05:53:58Z")

</div>

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:

```nohighlight
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!

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [March 13, 2022, 6:18am UTC](https://discourse.julialang.org/t/functions-mimic-pandas-apply-list/77813/2 "2022-03-13T06:18:42Z")

</div>

if you want to avoid copying data:

```julia
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
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']

```
