[Numpy-discussion] Numpy Enhancement Proposal: group_by functionality

Eelco Hoogendoorn hoogendoorn.eelco at gmail.com
Sun Jan 26 14:01:01 EST 2014


Alan:

The equivalent of that in my current draft would be group_by(keys, values),
which is shorthand for group_by(keys).group(values); a optional values
argument to the constructor of GroupBy is directly bound to return an
iterable over the grouped values; but we often want to bind different value
objects, with different operations, for the same set of keys, so it is
convenient to be able to delay the binding of the values argument. Also,
the third argument to group_by is an optional reduction function.


On Sun, Jan 26, 2014 at 6:57 PM, Alan G Isaac <alan.isaac at gmail.com> wrote:

> On 1/26/2014 12:02 PM, Stéfan van der Walt wrote:
> >   what would the output of
> >
> > ``group_by((key1, key2))``
>
>
> I'd expect something named "groupby" to behave as below.
> Alan
>
> def groupby(seq, key):
>    from collections import defaultdict
>    groups = defaultdict(list)
>    for item in seq:
>      groups[key(item)].append(item)
>    return groups
>
> print groupby(range(20), lambda x: x%2)
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140126/b102813b/attachment.html>


More information about the NumPy-Discussion mailing list