import numpy data = [2, 1, 5, 3, 4, 8, 10, 7, 9, 6, 11, 13, 12] q0 = numpy.quantile(data, 0) q1 = numpy.quantile(data, 0.25) q2 = numpy.quantile(data, 0.5) q3 = numpy.quantile(data, 0.75) q4 = numpy.quantile(data, 1) print("Quartile 0: ", q0) print("Quartile 1: ", q1) print("Quartile 2: ", q2) print("Quartile 3: ", q3) print("Quartile 4: ", q4)
The output of the above program will be:
Quartile 0: 1 Quartile 1: 4.0 Quartile 2: 7.0 Quartile 3: 10.0 Quartile 4: 13
Please note that if we sort the data, then the data becomes [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13].
Quartile 0 is the smallest number 1, and Quartile 4 is the largest number 13.
Quartile 2 is the median of the data 7.
Quartile 1 is the middle number between 1 and 7, and it is 4. And quartile 3 is the middle number between quartile 2 and quartile 4, and it is 10.
The numpy.quantile(data, q) function takes the dataset data and a number q between 0 and 1 as input. And it calculates the qth quantile of the given data. So, quartile 0 is 0th quantile, quartile 1 is the 0.25th quantile, quartile 2 is the 0.5th quantile, quartile 3 is the 0.75th quantile and quartile 4 is the 1th quantile.
What is Inter Quartile Range (IQR) of a dataset?
The difference between quartile 3 and quartile 1 is called the inter-quartile range of a dataset. In other words,
Inter-quartile range = (Q3 – Q1)
How to calculate the inter-quartile range of a dataset in Python?
We can calculate the inter-quartile range of a dataset in Python in the following way:






0 Comments