Python | Pandas Series.quantile()
Last Updated :
25 Nov, 2022
Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.quantile() function return value at the given quantile for the underlying data in the given Series object.
Syntax: Series.quantile(q=0.5, interpolation=’linear’)
Parameter :
q : float or array-like, default 0.5 (50% quantile)
interpolation : {‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’}
Returns : quantile : float or Series
Example #1: Use Series.quantile() function to return the desired quantile of the underlying data in the given Series object.
Python3
import pandas as pd
sr = pd.Series([ 10 , 25 , 3 , 11 , 24 , 6 ])
index_ = [ 'Coca Cola' , 'Sprite' , 'Coke' , 'Fanta' , 'Dew' , 'ThumbsUp' ]
sr.index = index_
print (sr)
|
Output : Now we will use Series.quantile() function to find the 40% quantile of the underlying data in the given series object.
Python3
result = sr.quantile(q = 0.4 )
print (result)
|
Output : As we can see in the output, the Series.quantile() function has successfully returned the desired quantile value of the underlying data of the given Series object. Example #2: Use Series.quantile() function to return the desired quantile of the underlying data in the given Series object.
Python3
import pandas as pd
sr = pd.Series([ 11 , 21 , 8 , 18 , 65 , 84 , 32 , 10 , 5 , 24 , 32 ])
print (sr)
|
Output : Now we will use Series.quantile() function to find the 90% quantile of the underlying data in the given series object.
Python3
result = sr.quantile(q = 0.9 )
print (result)
|
Output : As we can see in the output, the Series.quantile() function has successfully returned the desired quantile value of the underlying data of the given Series object.
Share your thoughts in the comments
Please Login to comment...