Repository navigation
first/last aggregations for DataFrame-/SeriesGroupBy - #3389
Merged
Merged
Conversation
mrocklin
reviewed
Apr 10, 2018
mrocklin
left a comment
Member
There was a problem hiding this comment.
This seems great to me. I also really appreciate the effort to clean up the testing infrastructure.
| (ddf.groupby('a')[['b', 'c']], df.groupby('a')[['b', 'c']]), | ||
| (ddf.groupby('a')[['b']], df.groupby('a')[['b']]), | ||
| (ddf.groupby(['a', 'b', 'c']), df.groupby(['a', 'b', 'c']))] | ||
| dask_group, pandas_group = grouper(ddf, df) |
Member
There was a problem hiding this comment.
I like this change.
Is there anything stopping us from simplifying the functions to lambda df: df.groupby...) and calling them twice here like
df = grouper(df)
ddf = groupber(ddf)
Contributor
Author
There was a problem hiding this comment.
@mrocklin thank you,
actually nothing stops, two arguments here are indeed redundant
```
In [1]: import pandas as pd, dask.dataframe as dd
In [2]: df = pd.DataFrame({'F': list('abcdef'),
'B': [4, 5, 4, 5, 5, 4],
'C': [7, 8, 9, 4, 2, 3],
'D': [1, 3, 5, 7, 1, 0],
'E': [5, 3, 6, 9, 2, 4],
'A': list('aaabbb')})
In [3]: ddf = dd.from_pandas(df, npartitions=3)
In [4]: ddf.groupby(by='A').agg({'B': 'mean', 'C': 'mean', 'D': 'first', 'E': 'last'}).compute()
Out[4]:
B C D E
A
a 4.333333 8.0 1 6
b 4.666667 3.0 7 4
In [5]: ddf.groupby(by='A')['D', 'E'].first().compute()
Out[5]:
D E
A
a 1 5
b 7 9
In [6]: ddf.groupby(by='A')['D', 'E'].last().compute()
Out[6]:
D E
A
a 5 6
b 0 4
```
almaleksia
force-pushed
the
first_last_groupby
branch
from
April 10, 2018 14:48
a72f2ea to
6d3b8d9
Compare
Member
|
This looks good to me. Merging. My apologies for the delay. Thank you also for cleaning up the test suite. That is very much appreciated! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
flake8 daskdocs/source/changelog.rstfor all changesand one of the
docs/source/*-api.rstfiles for new APIxref #3206