Python statistics.mode() Method

Python statistics.mode() method is “used to calculate the mode (central tendency) of the given numeric or nominal data set.”




data: It is required. The data values to be used (can be any sequence, list, or iterator.

Example 1: How to Use Python statistics.mode() Method

import statistics

listA = [19, 21, 46, 19, 18, 19]

In the above code, the number 19 is frequently appearing. So that is our mode.


Python Mode Function Example

Example 2

The mode is the statistical term that refers to the most frequently occurring number found in a set of numbers. The mode is detected by collecting and organizing data to count the frequency of each result.

import statistics

listUnique = [19, 21, 18, 30, 46]

The above list has unique elements inside the list. So mode does not work here. Instead, it will give us an error.


Python Statistics Tutorial

Example 3

To calculate the tuple’s mode, pass it as a parameter to the mode() function, and it will return the mode of data.

import statistics

data = (21, 19, 18, 46, 30, 18, 19, 21, 18)


Calculate Mode of Tuple in Python

That’s it.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.