How to calculate deciles in Python?

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.

See also  How to calculate geometric mean in Python?

deciles python

Calculating deciles in Python

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

You can use the quantiles function from the statistics module, specifying n=10, to calculate deciles.

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))