How to Apply the mode() Function of the statistics Module in Python (Example Code)

This tutorial explains how to apply the mode function of the statistics module in Python.

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 mode() Function of statistics Module

import statistics                                     # Load statistics
print(statistics.mode(x))                             # Get mode of list
# 1

Leave a Reply

Your email address will not be published.

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