-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: add quantile method to resample #22304
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -766,6 +766,24 @@ def size(self): | |
result = pd.Series([], index=result.index, dtype='int64') | ||
return result | ||
|
||
def quantile(self, q=0.5, **kwargs): | ||
""" | ||
Return value at the given quantile. | ||
|
||
.. versionadded:: 0.24.0 | ||
|
||
Parameters | ||
---------- | ||
q : float or array-like, default 0.5 (50% quantile) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add some See Also and point to the Series / groupby versions |
||
See Also | ||
-------- | ||
Series.quantile | ||
DataFrame.quantile | ||
DataFrameGroupBy.quantile | ||
""" | ||
return self._downsample('quantile', q=q, **kwargs) | ||
|
||
|
||
# downsample methods | ||
for method in ['sum', 'prod']: | ||
|
@@ -1060,7 +1078,8 @@ def _downsample(self, how, **kwargs): | |
|
||
if is_subperiod(ax.freq, self.freq): | ||
# Downsampling | ||
return self._groupby_and_aggregate(how, grouper=self.grouper) | ||
return self._groupby_and_aggregate(how, grouper=self.grouper, | ||
**kwargs) | ||
elif is_superperiod(ax.freq, self.freq): | ||
if how == 'ohlc': | ||
# GH #13083 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ | |
|
||
# The various methods we support | ||
downsample_methods = ['min', 'max', 'first', 'last', 'sum', 'mean', 'sem', | ||
'median', 'prod', 'var', 'ohlc'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add the test from the OP which compares 2 methods of getting the same result |
||
'median', 'prod', 'var', 'ohlc', 'quantile'] | ||
upsample_methods = ['count', 'size'] | ||
series_methods = ['nunique'] | ||
resample_methods = downsample_methods + upsample_methods + series_methods | ||
|
@@ -782,6 +782,15 @@ def test_resampler_is_iterable(self): | |
assert rk == gk | ||
assert_series_equal(rv, gv) | ||
|
||
def test_resample_quantile(self): | ||
# GH 15023 | ||
s = self.create_series() | ||
q = 0.75 | ||
freq = 'H' | ||
result = s.resample(freq).quantile(q) | ||
expected = s.resample(freq).agg(lambda x: x.quantile(q)) | ||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
class TestDatetimeIndex(Base): | ||
_index_factory = lambda x: date_range | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a versionadded tag