The statistics.quantiles()
method in Python is used to return the quantiles that correspond to the numbers n
contained in the iterable containing data.
To explain further, when you assign a number to the n
parameter, the function returns the corresponding n-1
quartiles. For example, if the n
parameter is assigned as 10 for deciles, the statistics.quantiles()
method will return 10-1=9
cut points of equal intervals.
A quantile defines a particular data set. In other words, a quantile determines how many values in a distribution are above or below a certain limit. A quantile can be a quartile, percentiles, and quintile.
Statistics.quantiles(data, *, n=4, method = ‘exclusive’)
Parameter | Description |
data | An iterable that contains the data from which you want to obtain the quantiles. This is required. |
n | The number of quantiles you want. This parameter takes an integer value, which is 4 by default. This is optional. |
method | The method by which the quantiles are to be calculated; exclusive or inclusive. It is exclusive by default. |
The statistics.quantiles()
method returns a list that contains the numeric values of the upper n-1
quantiles.
Now, let’s use the statistics.quantiles()
method to return the upper quartile values of a data set.
import statisticsdata1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]# to return the upper three quartilesthird_quartiles = statistics.quantiles(data1, n=4)print('The third quartile of the given data set is', third_quartiles)
statistics
module.data1
.statistics.quantiles()
method to return the three upper
quartiles of the data set and assign it to a variable called third_quartiles
.third_quartile
.