Python statistics module

Python statistics module provides the functions to mathematical statistics of numeric data. There are some popular statistical functions defined in this module.

mean() function

The mean() function is used to calculate the arithmetic mean of the numbers in the list.

Example

import statistics
# list of positive integer numbers 
datasets = [5274268]
x = statistics.mean(datasets)
# Printing the mean 
print("Mean is :", x)

Output:

Mean is : 4.857142857142857

median() function

The median() function is used to return the middle value of the numeric data in the list.

Example

import statistics
datasets = [4, -566945, -2]
# Printing median of the 
# random data-set 
print("Median of data-set is : % s "
% (statistics.median(datasets)))

Output:

Median of data-set is : 4.5

mode() function

The mode() function returns the most common data that occurs in the list.

Example

import statistics
# declaring a simple data-set consisting of real valued positive integers. 
dataset =[2477223668]
# Printing out the mode of given data-set 
print("Calculated Mode % s" % (statistics.mode(dataset)))

Output:

Calculated Mode 2

stdev() function

The stdev() function is used to calculate the standard deviation on a given sample which is available in the form of the list.

Example

import statistics
# creating a simple data - set 
sample = [7891011]
# Prints standard deviation 
print("Standard Deviation of sample is % s "
% (statistics.stdev(sample)))

Output:

Standard Deviation of sample is 1.5811388300841898

median_low()

The median_low function is used to return the low median of numeric data in the list.

Example

import statistics
# simple list of a set of integers 
set1 = [462577]
# Note: low median will always be a member of the data-set.   
# Print low median of the data-set 
print("Low median of data-set is % s "
% (statistics.median_low(set1)))

Output:

Low median of the data-set is 5

median_high()

The median_high function is used to return the high median of numeric data in the list.

Example

import statistics
# list of set of the integers 
dataset = [217619]
print("High median of data-set is %s "
% (statistics.median_high(dataset)))

Output:

High median of the data-set is 6

Leave a Reply

Your email address will not be published. Required fields are marked *