From 026ae2d106fd328c719dda1db7b38901b467ae5b Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Mon, 2 Jan 2017 01:57:22 +0530 Subject: [PATCH 1/2] Add quantile shortcut --- pandas/core/groupby.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index 7eba32b4932d0..7f50434354ee0 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -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): + """ + 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): From a3b713beffd1d78b7a3b80c3275410654cce30ca Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Mon, 2 Jan 2017 00:42:43 +0530 Subject: [PATCH 2/2] Add quantile shortcut --- pandas/tseries/resample.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pandas/tseries/resample.py b/pandas/tseries/resample.py index e6d500144fa44..4332b704c1c1e 100755 --- a/pandas/tseries/resample.py +++ b/pandas/tseries/resample.py @@ -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