Pandas example of groupby
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jan 26 12:50:52 PST 2015
On 1/26/15 12:31 PM, H. S. Teoh via Digitalmars-d wrote:
> As far as I know, the current groupBy docs explain quite clearly what it
> does.
I agree. That said, perhaps a change of name would avoid confusion. I
like groupBy as we currently define it, it's straight within the spirit
of D. However, some people may legitimately expect it does global
processing and groups all identical keys together.
So here's what I think we should do:
1. Rename our current groupBy to chunkBy
2. Change code to have chunkBy with binary predicates return tuples, as
discussed
3. Add a method called groupEquivalent to SortedRange. It takes no
predicate (because predicate already is embedded in SortedRange). It
groups together elements that are equivalent according to the sorting
order. Returns a range of ranges (similar to what groupBy returns now).
4. Perhaps add a global chunkEquivalent as an alias for groupBy!((a, b)
=> a == b).
So then in order to get relational group-by semantics by sorting, one
would write range.sort!(predicate).groupEquivalent...
Andrei
More information about the Digitalmars-d
mailing list