How to use function statistics in Python? - with practical example

Python provides a statistics module that allows us to perform statistical calculations easily. Let's explore how to use the statistics function in Python with two different examples. Example 1: Calculating the mean of a list of numbers Step 1: Import the statistics module Step 2: Create a list of numbers Step 3: Use the mean() function from the statistics module to calculate the mean of the list
import statistics

numbers = [2, 4, 6, 8, 10]
mean = statistics.mean(numbers)
print("Mean:", mean)

Example 2: Calculating the median of a list of numbers Step 1: Import the statistics module Step 2: Create a list of numbers Step 3: Use the median() function from the statistics module to calculate the median of the list
import statistics

numbers = [3, 6, 9, 12, 15]
median = statistics.median(numbers)
print("Median:", median)

By following these steps and using the functions from the statistics module in Python, we can easily perform statistical calculations such as finding the mean and median of a list of numbers.

Comments

Popular posts from this blog

What are the different types of optimization algorithms used in deep learning?

What are the different evaluation metrics used in machine learning?

What is the difference between a module and a package in Python?