Percentile rank of a column in pandas python – (percentile value)

Percentile rank of a column in pandas python is carried out using rank() function with argument (pct=True) . Let’s see how to

  •  Get the percentile rank of a column in pandas (percentile value) dataframe in python With an example

First let’s create a dataframe


import pandas as pd
import numpy as np

#Create a DataFrame
df1 = {
     'Name':['George','Andrea','micheal','maggie','Ravi','Xien','Jalpa'],
   'Mathematics_score':[62,47,55,74,32,77,86]}

df1 = pd.DataFrame(df1,columns=['Name','Mathematics_score'])
print(df1)

df1 will be

Percentile rank of a column in pandas python 1

 

Percentile rank of a column in a pandas dataframe python 

Percentile rank of the column (Mathematics_score) is computed using rank() function and with argument  (pct=True),  and stored in a new column namely “percentile_rank”  as shown below


df1['Percentile_rank']=df1.Mathematics_score.rank(pct=True)
print(df1)

so the resultant dataframe will be

Percentile rank of a column in pandas python 2

 

Percentile rank of a column in pandas python - (percentile value)                                                                                                                Percentile rank of a column in pandas python - (percentile value) next