Print values above 75th percentile from series Using Quantile using Pandas
Last Updated :
31 Jul, 2023
Given a series, the task is to print all the elements that are above the 75th percentile using Pandas in Python. There is a series of data, we have to find all the values of the series object whose value is greater than the 75th Percentile.
Print values above 75th percentile from series Using Quantile
- Create a series object of any dataset
- We will calculate 75th percentile using the quantile function of the pandas series
- We will apply for loop for iterating all the values of series object
- Inside for loop, we’ll check whether the value is greater than the 75th quantile value that is calculated in step(2) if greater then print it.
Python3
import pandas as pd
import numpy as np
arr = np.array([ 42 , 12 , 72 , 85 , 56 , 100 ])
Ser1 = pd.Series(arr)
print (Ser1)
quantile_value = Ser1.quantile(q = 0.75 )
print ( "75th Percentile is:" , quantile_value)
print ( "Values that are greater than 75th percentile are:" )
for val in Ser1:
if (val > quantile_value):
print (val)
|
Output:
0 42
1 12
2 72
3 85
4 56
5 100
dtype: int32
75th Percentile is: 81.75
Values that are greater than 75th percentile are:
85
100
Explanation:
We have made a series object from an nd array and used the quantile() method to find the75% quantile or 75th percentile value of the data in the given series object and then use a for loop to find out all values of the series that are above the 75th percentile.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...