Open In App

Print values above 75th percentile from series Using Quantile using Pandas

Last Updated : 31 Jul, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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




# importing pandas module
import pandas as pd
 
# importing numpy module
import numpy as np
 
# Making an array
arr = np.array([42, 12, 72, 85, 56, 100])
 
# creating a series
Ser1 = pd.Series(arr)
 
# printing this series
print(Ser1)
 
# calculating quantile/percentile value
quantile_value = Ser1.quantile(q=0.75)
 
# printing quantile/percentile value
print("75th Percentile is:", quantile_value)
print("Values that are greater than 75th percentile are:")
 
# Running a loop and
# printing all elements that are above the
# 75th percentile
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.


Similar Reads

Pandas DataFrame quantile() Method | Find Quantile Values
Python is a great language for data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages, making importing and analyzing data much easier.  Pandas quantile() function returns values at the given quantile over the requested axis.  Note: In each of any set of values of a variate which
2 min read
Python | Pandas Series.quantile()
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
2 min read
Percentile rank of a column in a Pandas DataFrame
Let us see how to find the percentile rank of a column in a Pandas DataFrame. We will use the rank() function with the argument pct = True to find the percentile rank. Example 1 : # import the module import pandas as pd # create a DataFrame data = {'Name': ['Mukul', 'Rohan', 'Mayank', 'Shubham', 'Aakash'], 'Location' : ['Saharanpur', 'Meerut', 'Agr
1 min read
Quantile and Decile rank of a column in Pandas-Python
Let's see how to find the Quantile and Decile ranks of a column in Pandas. We will be using the qcut() function of the pandas module. pandas.qcut() Pandas library's function qcut() is a Quantile-based discretization function. This means that it discretize the variables into equal-sized buckets based on rank or based on sample quantiles. Syntax : pa
2 min read
Finding the Quantile and Decile Ranks of a Pandas DataFrame column
A Quantile is where a sample is divided into equal-sized, adjacent, subgroups. The median is a quantile; the median is placed in a probability distribution so that exactly half of the data is lower than the median and half of the data is above the median. The median cuts a distribution into two equal areas and so it is sometimes called 2-quantile.
4 min read
Pandas Series dt.weekofyear Method | Get Week of Year in Pandas Series
The dt.weekofyear attribute returns a Series containing the week ordinal of the year in the underlying data of the given series object. Example C/C++ Code import pandas as pd sr = pd.Series(['2012-10-21 09:30', '2019-7-18 12:30', '2008-02-2 10:30', '2010-4-22 09:25', '2019-11-8 02:22']) idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5'] sr.index =
2 min read
Pandas Series dt.minute | Extract Minute from DateTime Series in Pandas
Pandas Series.dt.minute attribute returns a NumPy array containing the minutes of the DateTime in the underlying data of the given series object. Example C/C++ Code import pandas as pd sr = pd.Series(['2012-10-21 09:30', '2019-7-18 12:30', '2008-02-2 10:30', '2010-4-22 09:25', '2019-11-8 02:22']) idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5']
2 min read
Pandas Series dt.dayofweek | Get Day of Week from DateTime Series in Pandas
Pandas dt.dayofweek attribute returns the day of the week from the given DateTime Series Object. It is assumed the week starts on Monday, which is denoted by 0, and ends on Sunday which is denoted by 6. Example: C/C++ Code import pandas as pd sr = pd.Series(['2012-10-21 09:30', '2019-7-18 12:30', '2008-02-2 10:30', '2010-4-22 09:25', '2019-11-8 02:
2 min read
Pandas Series dt.freq | Retrieve Frequency of Pandas Time Series
Pandas dt.freq attribute returns the time series frequency applied on the given series object if any, else it returns None. Examples C/C++ Code import pandas as pd sr = pd.Series(['2012-12-31', '2019-1-1 12:30', '2008-02-2 10:30', '2010-1-1 09:25', '2019-12-31 00:00']) idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5'] sr.index = idx sr = pd.to_da
2 min read
Pandas Series dt.daysinmonth | Get Number of Days in Month in Pandas Series
The dt.daysinmonth attribute returns the number of days in the month for the given DateTime series object. Example C/C++ Code import pandas as pd sr = pd.Series(['2012-12-31', '2019-1-1 12:30', '2008-02-2 10:30', '2010-1-1 09:25', '2019-12-31 00:00']) idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5'] sr.index = idx sr = pd.to_datetime(sr) result
2 min read
Practice Tags :