ENH: add quantile method to resample · Issue #15023 · pandas-dev/pandas (original) (raw)

Problem description

The quantile method is currently not supported on resample. While resample(...).agg(lambda x: x.quantile(..)) works fine, it would be nice to add the resample(..).quantile(..) shortcut.

Code Sample

In [19]: ts = pd.Series(range(20), index=pd.date_range('2016-01-01', periods=20))

In [21]: ts.resample('W').agg(lambda x: x.quantile(0.75))
Out[21]: 
2016-01-03     1.5
2016-01-10     7.5
2016-01-17    14.5
2016-01-24    18.5
Freq: W-SUN, dtype: float64

So it would be nice the following would give the same result:

In [22]: ts.resample('W').quantile(0.75)
/home/joris/miniconda3/envs/dev/bin/ipython:1: FutureWarning: 
.resample() is now a deferred operation
You called quantile(...) on this deferred object which materialized it into a series
by implicitly taking the mean.  Use .resample(...).mean() instead
  #!/home/joris/miniconda3/envs/dev/bin/python
Out[22]: 14.25

The fact that this currently implicitly takes the mean before calculating the quantile (ts.resample('W').mean().quantile(0.75)) would make this change slightly API breaking.

Using pandas master, 0.19.0+289.g1bf94c8