Skip to content

Commit

Permalink
add collect list example
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray Bell committed Feb 23, 2020
1 parent 0ecb05f commit 205740d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/source/dataframe-groupby.rst
Expand Up @@ -207,3 +207,16 @@ Finally, we create and use the aggregation
a
a 2
b 4
Another example of a custom aggregation is the Dask DataFrame version of
Pandas' ``groupby('g').agg(list)``:

.. code-block:: python
>>> import itertools as it
>>> collect_list = dd.Aggregation(
... name="collect_list",
... chunk=lambda s: s.apply(list),
... agg=lambda s0: s0.apply(lambda chunks: list(it.chain.from_iterable(chunks))),
... )
>>> df.groupby('g').agg(collect_list)

0 comments on commit 205740d

Please sign in to comment.