Computing Quantiles-Percentiles, Quintiles, Deciles, Quarters

Overview:

  • Similar to Mean, Median and Mode a Quantile is also a statistical measure of location.
  • Quantile indicates a point in distribution below which, a portion of the data lies.
  • Quantile is also called as Fractile as it locates the place in distribution below which, a specific fraction of the distribution lies.
  • Quantile is a generic term.  The measures percentile, quintile, decile and quartiles are all quantiles that divide a distribution into portions.
    • Percentiles: They divide the distribution into hundredths.
    • Quintiles: They divide the distribution as parts of fifths.
    • Deciles: They divide the distribution into parts of tenths.
    • Quarters: They divide the distribution into quarters.

Finding quantiles for a Pandas.series:

  • Series.quartile() function returns the specific value of a quantile based on the parameter ‘q‘.
  • Here is a table that summarizes various quantiles:

Value of ‘q‘

Quantile

0.05

1st quintile

0.1

1st Decile/2nd quintile

0.2

2nd Decile/4th quintile

0.25

1st quarter/5th quintile/ 25th percentile

0.3

3rd Decile/6th quintile/ 30th percentile

0.4

4th Decile/8th quintile/ 40th percentile

0.5

1st half/2nd quarter/5th Decile/10th quintile/50th percentile

0.6

6th Decile/12th quintile/60th percentile

0.7

7th Decile/14th quintile/70th percentile

0.75

3rd quarter/15th quintile/ 75th percentile

0.9

9th Decile/18th quintile/90th percentile

1.0

10th Decile/20th quintile/100th percentile

 

Example:

The example below loads a JSON string of student scores into a pandas.series and calculates the 1st Quarter, 2nd Quarter and 3rd Quarter scores. Also it finds the 1st and 100th percentiles scores.

# Example Python program that calculates quantiles

import pandas as pds

 

# Read a JSON file

scoreFile = "./scores.json";

dataFrame = pds.read_json(scoreFile);

 

# Load the score column into a pandas.Series

scores = dataFrame["Score"];

print("Scores as loaded into the pandas.Series instance:");

print(scores);

 

print("First Quartile:%.2f"%scores.quantile(.25));

print("Second Quartile:%.2f"%scores.quantile(.5));

print("Third Quartile:%.2f"%scores.quantile(.75));

print("100th Percentile:%.2f"%scores.quantile(1));

print("1st Percentile:%.2f"%scores.quantile(.1));

 

Output:

Scores as loaded into the pandas.Series instance:

0    65

1    61

2    77

3    82

4    67

5    55

6    53

7    85

8    67

9    96

Name: Score, dtype: int64

First Quartile:62.00

Second Quartile:67.00

Third Quartile:80.75

100th Percentile:96.00

1st Percentile:54.80

 

 


Copyright 2023 © pythontic.com