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 |
1^{st} quintile |
0.1 |
1^{st} Decile/2^{nd} quintile |
0.2 |
2^{nd} Decile/4^{th} quintile |
0.25 |
1^{st} quarter/5^{th} quintile/ 25^{th} percentile |
0.3 |
3^{rd} Decile/6^{th} quintile/ 30^{th} percentile |
0.4 |
4^{th} Decile/8^{th} quintile/ 40^{th} percentile |
0.5 |
1^{st} half/2^{nd} quarter/5^{th} Decile/10^{th} quintile/50^{th} percentile |
0.6 |
6^{th} Decile/12^{th} quintile/60^{th} percentile |
0.7 |
7^{th} Decile/14^{th} quintile/70^{th} percentile |
0.75 |
3^{rd} quarter/15^{th} quintile/ 75^{th} percentile |
0.9 |
9^{th} Decile/18^{th} quintile/90^{th} percentile |
1.0 |
10^{th} Decile/20^{th} quintile/100^{th} percentile |
Example:
The example below loads a JSON string of student scores into a pandas.series and calculates the 1^{st} Quarter, 2^{nd} Quarter and 3^{rd} Quarter scores. Also it finds the 1^{st} and 100^{th} 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 |