
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to get the nth percentile of a Pandas series?
A percentile is a term used in statistics to express how a score compares to other scores in the same set. In this program, we have to find nth percentile of a Pandas series.
Algorithm
Step 1: Define a Pandas series. Step 2: Input percentile value. Step 3: Calculate the percentile. Step 4: Print the percentile.
Example Code
import pandas as pd series = pd.Series([10,20,30,40,50]) print("Series:\n", series) n = int(input("Enter the percentile you want to calculate: ")) n = n/100 percentile = series.quantile(n) print("The {} percentile of the given series is: {}".format(n*100, percentile))
Output
Series: 0 10 1 20 2 30 3 40 4 50 dtype: int64 Enter the percentile you want to calculate: 50 The 50.0 percentile of the given series is: 30.0
Explanation
The quantile function in the Pandas library takes values only between 0 and 1 as parameters. Therefore, we have to divide the percentile value by 100 before passing it to the quantile function.
- Related Articles
- How to get nth row in a Pandas DataFrame?
- How to Get the Position of Max Value of a pandas Series?
- How to Get the Position of Minimum Value of a pandas Series?
- How to get the nth value of a Fibonacci series using recursion in C#?
- How to get the index and values of series in Pandas?
- How to get the length, size, and shape of a series in Pandas?
- How to get few rows from a Series in Pandas?
- How to Get the values from the pandas series between a specific time?
- How to get the final rows of a time series data using pandas series.last() method?
- How to sort a Pandas Series?
- How to check the data type of a pandas series?
- Nth element of the Fibonacci series JavaScript
- How to append elements to a Pandas series?
- How to append a pandas Series object to another Series in Python?
- How to calculate the frequency of each item in a Pandas series?

Advertisements