From 205740dff513f85f2362b4e979a9675f9638080f Mon Sep 17 00:00:00 2001 From: Ray Bell Date: Sun, 23 Feb 2020 00:17:34 -0500 Subject: [PATCH] add collect list example --- docs/source/dataframe-groupby.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/source/dataframe-groupby.rst b/docs/source/dataframe-groupby.rst index 46422b1c50e7..3156f3eed6ba 100644 --- a/docs/source/dataframe-groupby.rst +++ b/docs/source/dataframe-groupby.rst @@ -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)