statistics.median() Function in Python – How to Apply (Example Code)

On this page you’ll learn how to use the statistics.median function in the Python programming language.

Creation of Example Data

x = [1, 3, 3, 7, 1, 3, 5, 1, 2, 2, 1, 2, 1, 3, 1, 7]  # Constructing a list in Python
print(x)                                              # Displaying the example list
# [1, 3, 3, 7, 1, 3, 5, 1, 2, 2, 1, 2, 1, 3, 1, 7]

Example: Applying median() Function of statistics Module

import statistics                                     # Import statistics
print(statistics.median(x))                           # Get median of list
# 2.0

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top