Pandas core resample Resampler function quantile() in Python
The Pandas core resample Resampler function quantile() used to retrieve value at the given quantile. It returns a DataFrame or Series that includes quantile of values within each group.
Syntax
 1 Resampler.quantile(q = 0.5, **kwargs)
q : it can be a float or array with value that is in between the 0 <= q <= 1, the quantile(s) to compute. If not specified the default value will be 0.5 (50% quantile).
quantile() function
 1 import pandas as pd
 2 
 3 idx = pd.DatetimeIndex(['2023-01-01', '2023-01-5', '2023-01-10',
 4  '2023-02-01', '2023-02-10', '2023-02-15'])
 5 ser = pd.Series([1, 2, 1, 3, 5, 7], index = idx)
 6 
 7 sample = ser.resample('MS')
 8 
 9 res = sample.quantile()
 10 print('The quantile of each group :')
 11 print(res)
In the above example, a Series object is created by passing an array and index. A Resampler function quantile() called that computes the quantile for each elements within group. The result is assign to the variable that will be printed on console.
Output
 1 The quantile of each group :
 2 2023-01-01    1.0
 3 2023-02-01    5.0
 4 Freq: MS, dtype: float64

Example 2

Example 2
 1 import pandas as pd
 2 
 3 idx = pd.date_range('20230101', periods = 5, freq = 'h')
 4 ser = pd.Series([1, 2, 3, 4, 5], index = idx)
 5 
 6 sample = ser.resample('2h')
 7 
 8 res = sample.quantile()
 9 print('The quantile of each group :')
 10 print(res)
In the above example, a Series object is created by passing an array and index. A Resampler function quantile() called that computes the quantile for each elements within group.
Output
 1 The quantile of each group :
 2 2023-01-01 00:00:00    1.5
 3 2023-01-01 02:00:00    3.5
 4 2023-01-01 04:00:00    5.0
 5 Freq: 2h, dtype: float64
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us