How to calculate deciles in Python?

By Shivang Yadav Last updated : December 7, 2023

Prerequisite

To understand the calculation of deciles, you should have the knowledge of the following Python's topics:

Deciles

Deciles means fragmenting data into 10 subsets of equal size. For this, the set needs to be arranged in ascending order. Each decile represents 10% weightage of the set.

Formula:

Position of Dk = ((k*(n+1))/10)

Where,

  • k: deciles number (1 for the first decile).
  • n: n is the data count in the dataset.

Calculating deciles in Python

To calculate deciles, you can use the numpy.percentile() method by passing the data set and numpy.arrange(0, 100, 10).

Python program to calculate deciles

Here, we have an array as data values and calculating the deciles.

# Program to calculate deciles in python
import numpy as np

dataArr = np.array([43, 23, 7, 87, 97, 11, 90, 65, 87, 23])
print("Value of dataset are ", dataArr)

# calculate deciles of data
deciles = np.percentile(dataArr, np.arange(0, 100, 10))
print("Deciles Value : ", deciles)

Output

The output of the above program is:

Value of dataset are  [43 23  7 87 97 11 90 65 87 23]
Deciles Value :  [ 7.  10.6 20.6 23.  35.  54.  73.8 87.  87.6 90.7]

Python NumPy Programs »


Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.