The statistics module in Python provides functions for mathematical statistics on numeric data.
It includes functions for calculating measures such as mean, median, mode, standard deviation, and more.
statistics module is part of the Python Standard Library and offers various methods to compute mathematical statistics on numerical data.
Here's an overview of some common functionalities provided by the statistics module:
Computes the arithmetic mean of the data from the list.
# Declare the statistics module import statistics data = [1, 2, 3, 4, 5, 6, 7, 8, 9] # Printing the result print(statistics.mean(data)) # Output: 5
Computes the median (middle value) of the data from the list.
# Declare the statistics module import statistics data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # Printing the result print(statistics.median(data)) # Output: 5.5
Computes the mode (most common value) of the data from the list.
# Declare the statistics module import statistics data = [1, 2, 3, 4, 5, 5, 6, 6, 6, 7] # Printing the result print(statistics.mode(data)) # Output: 6
Computes the variance of the data from the list.
import statistics data = [ 2, 4, 6, 8, 10] # Printing the result print(statistics.variance(data)) # Output: 10
Computes the standard deviation of the data from the list.
import statistics data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # Printing the result print(statistics.stdev(data)) # Output: 3.0276503540974917
Computes the harmonic mean of the data from the list.
import statistics data = [2, 4, 6, 8] # Printing the result print(statistics.harmonic_mean(data)) # Output: 3.84
Computes the low and high median of the data from the list, respectively.
import statistics data = [1, 3, 5, 7, 9, 11] # Printing the result print(statistics.median_low(data)) # Output: 5 # Printing the result print(statistics.median_high(data)) # Output: 7
Computes the median of grouped continuous data from the list.
import statistics data = [10, 20, 30, 40, 50] # Grouped data with intervals of 10 # Printing the result print(statistics.median_grouped(data)) # Output: 30.0
These are just a few examples of what we can do with the "statistics" module.
It provides many more functions for the "statistical" analysis of data.
Always import the "statistics" module (import statistics) before using its functions.
Additionally, note that the "statistics" module is available in "Python 3.x" and above.