w3resource

Pandas Series: quantile() function

Value at the given quantile

The quantile() function is used to get value at the given quantile.

Syntax:

Series.quantile(self, q=0.5, interpolation='linear')
Pandas Series quantile image

Parameters:

Name Description Type/Default Value Required / Optional
q 0 <= q <= 1, the quantile(s) to compute. float or array-like
Default Value: 0.5 (50% quantile)
Required
interpolation This optional parameter specifies the interpolation method to use, when the desired quantile lies between two data points i and j:
  • linear: i + (j - i) * fraction, where fraction is the fractional part of the index surrounded by i and j.
  • lower: i.
  • higher: j.
  • nearest: i or j whichever is nearest.
  • midpoint: (i + j) / 2.
{‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’} Required

Returns: float or Series
If q is an array, a Series will be returned where the index is q and the values are the quantiles, otherwise a float will be returned.

Example:

Python-Pandas Code:

import numpy as np
import pandas as pd
s = pd.Series([2, 3, 4, 5])
s.quantile(.5)

Output:

3.5
Pandas Series quantile image

Python-Pandas Code:

import numpy as np
import pandas as pd
s = pd.Series([2, 3, 4, 5])
s.quantile([.15, .5, .55])

Output:

0.15    2.45
0.50    3.50
0.55    3.65
dtype: float64

Previous: Product of the values for the requested Pandas axis
Next: Compute numerical data ranks along axis



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/pandas/series/series-quantile.php