Skip to content

[WIP]: Add quantile shortcut #15032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,22 @@ def mean(self, *args, **kwargs):
f = lambda x: x.mean(axis=self.axis)
return self._python_agg_general(f)

@Substitution(name='groupby')
@Appender(_doc_template)
def quantile(self, *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what you are doing here, this doesn't affect .resample.

but more importantly w/o tests it is impossible to tell.

"""
Compute quantile of groups, excluding missing values
"""
nv.validate_groupby_func('quantile', args, kwargs)
try:
return self._cython_agg_general('quantile')
except GroupByError:
raise
except Exception: # pragma: no cover
self._set_group_selection()
f = lambda x: x.quantile(axis=self.axis)
return self._python_agg_general(f)

@Substitution(name='groupby')
@Appender(_doc_template)
def median(self):
Expand Down
17 changes: 17 additions & 0 deletions pandas/tseries/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,23 @@ def aggregate(self, arg, *args, **kwargs):
agg = aggregate
apply = aggregate

def quantile(self, arg, *args, **kwargs):
"""
quantile method on resample - `resample(..).quantile(..)`
is a short-cut to `resample.agg(lambda x: x.quantile(0.75))`
Parameters
----------
arg : lambda function

Examples
--------
>>> resampled.quantile(0.75)

Returns
-------
"""
return self.agg(lambda x: x.quantile(arg), *args, **kwargs)

def transform(self, arg, *args, **kwargs):
"""
Call function producing a like-indexed Series on each group and return
Expand Down