Skip to content

ENH: allow multiple rolling quantiles in one pass #12093

Closed
@StephenKappel

Description

@StephenKappel

Currently, rolling_quantile() accepts only a single float for the quantile argument. I find myself wanting to compute multiple quantiles over the same data. Instead of doing three calls to rolling_quantile(), I'd like to be able to call rolling_quantile() once with a sequence of floats as the quantile argument and get back a list of results. This has benefits both in terms of code conciseness and efficiency.

This suggested behavior would be analogous to how np.percentile works. http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.percentile.html

Currently:

>>> import pandas as pd
>>> ser = pd.Series(np.array([1,2,3,4,5,6,7,8,9]))
>>> ser.rolling(window=3).quantile(quantile=0.5)
0   NaN
1   NaN
2     2
3     3
4     4
5     5
6     6
7     7
8     8
dtype: float64

Desired enhancement:

>>> ser.rolling(window=3).quantile(quantile=[0.25,0.5,1])
[0   NaN
1   NaN
2     1
3     2
4     3
5     4
6     5
7     6
8     7
dtype: float64, 0   NaN
1   NaN
2     2
3     3
4     4
5     5
6     6
7     7
8     8
dtype: float64, 0   NaN
1   NaN
2     3
3     4
4     5
5     6
6     7
7     8
8     9
dtype: float64]

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementPerformanceMemory or execution speed performanceWindowrolling, ewma, expandingquantilequantile method

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions