Open In App

Python | Pandas Series.quantile()

Last Updated : 25 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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




# importing pandas as pd
import pandas as pd
 
# Creating the Series
sr = pd.Series([10, 25, 3, 11, 24, 6])
 
# Create the Index
index_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp']
 
# set the index
sr.index = index_
 
# Print the series
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




# return the value of 40 % quantile
result = sr.quantile(q = 0.4)
 
# Print the result
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




# importing pandas as pd
import pandas as pd
 
# Creating the Series
sr = pd.Series([11, 21, 8, 18, 65, 84, 32, 10, 5, 24, 32])
 
# Print the series
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




# return the value of 90 % quantile
result = sr.quantile(q = 0.9)
 
# Print the result
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.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads