@@ -4468,7 +4468,7 @@ def mode(self, axis=0, numeric_only=False):
4468
4468
f = lambda s : s .mode ()
4469
4469
return data .apply (f , axis = axis )
4470
4470
4471
- def quantile (self , q = 0.5 , axis = 0 , numeric_only = True ):
4471
+ def quantile (self , q = 0.5 , axis = 0 , numeric_only = True , interpolation = 'linear' ):
4472
4472
"""
4473
4473
Return values at the given quantile over requested axis, a la
4474
4474
numpy.percentile.
@@ -4479,6 +4479,14 @@ def quantile(self, q=0.5, axis=0, numeric_only=True):
4479
4479
0 <= q <= 1, the quantile(s) to compute
4480
4480
axis : {0, 1}
4481
4481
0 for row-wise, 1 for column-wise
4482
+ interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}
4483
+ Specifies the interpolation method to use, when the desired quantile lies between two data points i and j:
4484
+ linear: i + (j - i) * fraction, where fraction is the fractional part of the index surrounded by i and j.
4485
+ lower: i.
4486
+ higher: j.
4487
+ nearest: i or j whichever is nearest.
4488
+ midpoint: (i + j) / 2.
4489
+
4482
4490
4483
4491
Returns
4484
4492
-------
@@ -4512,7 +4520,7 @@ def quantile(self, q=0.5, axis=0, numeric_only=True):
4512
4520
else :
4513
4521
squeeze = False
4514
4522
4515
- def f (arr , per ):
4523
+ def f (arr , per , interpolation ):
4516
4524
if arr ._is_datelike_mixed_type :
4517
4525
values = _values_from_object (arr ).view ('i8' )
4518
4526
else :
@@ -4521,7 +4529,7 @@ def f(arr, per):
4521
4529
if len (values ) == 0 :
4522
4530
return NA
4523
4531
else :
4524
- return _quantile (values , per )
4532
+ return _quantile (values , per , interpolation = interpolation )
4525
4533
4526
4534
data = self ._get_numeric_data () if numeric_only else self
4527
4535
if axis == 1 :
@@ -4532,7 +4540,7 @@ def f(arr, per):
4532
4540
is_dt_col = data .dtypes .map (com .is_datetime64_dtype )
4533
4541
is_dt_col = is_dt_col [is_dt_col ].index
4534
4542
4535
- quantiles = [[f (vals , x ) for x in per ]
4543
+ quantiles = [[f (vals , x , interpolation ) for x in per ]
4536
4544
for (_ , vals ) in data .iteritems ()]
4537
4545
result = DataFrame (quantiles , index = data ._info_axis , columns = q ).T
4538
4546
if len (is_dt_col ) > 0 :
0 commit comments