Computing quantiles-Percentiles, Quintiles, Deciles, Quarters

Quantile is a measure of location on a statistical distribution. The series.quantile() method finds the location below which the specific fraction of the data lies. The Python example loads a JSON file, loads scores into a pandas.Series and finds the first quarter, second quarter, third quarter, 1st percentile and 100th percentile.

Series Computations Updated 13 Aug 2019 2 min read

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.051st quintile
0.11st Decile/2nd quintile
0.22nd Decile/4th quintile
0.251st quarter/5th quintile/ 25th percentile
0.33rd Decile/6th quintile/ 30th percentile
0.44th Decile/8th quintile/ 40th percentile
0.51st half/2nd quarter/5th Decile/10th quintile/50th percentile
0.66th Decile/12th quintile/60th percentile
0.77th Decile/14th quintile/70th percentile
0.753rd quarter/15th quintile/ 75th percentile
0.99th Decile/18th quintile/90th percentile
1.010th 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.

python
# 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

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