How to Calculate Deciles in Python Using statistics.quantiles (Decile Definition and Example)

Deciles divide a dataset into ten equal parts, each representing 10% of the data. For example, the first decile represents the point below which 10% of the data falls, the second decile represents the point below which 20% of the data falls, and so on.

Let’s see how to calculate deciles in Python using the statistics.quantiles function with n=10, which returns the cut points that split your data into ten equal parts.

See also  How to Calculate Mode in Python (statistics.mode, NumPy bincount/argmax, and Examples)

deciles python

Calculating deciles in Python

To calculate deciles, we need to import the statistics module.

To calculate deciles in Python, call statistics.quantiles(x, n=10) on your data list, which produces the nine decile values marking the 10%, 20%, …, 90% positions in the sorted dataset.

import statistics as s

x = [1, 5, 7, 5, 43, 43, 8, 43, 6, 65, 63, 42, 1, 76, 43, 87, 53, 54]

deciles = s.quantiles(x, n=10)
print("Deciles are: " + str(deciles))