# How to find mode in Python

The** mode** of a set of values can be said as the value that appears most often. A mode of a continuous probability distribution is often considered to be any value x at which its probability density function has a local maximum value, so any peak is a mode.

The `mode()`

function in the statistics module can be used to find mode in Python. This function returns the robust measure of a central data point in a given range of data-sets.

Example:

# mode() function import statistics # mode of a list li = [1, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6] #mode of tuple t = (2, 5, 3, 7, 3, 2, 6, 2, 5, 2, 2) print("Mode of the given data set is {}".format(statistics.mode(li))) print("Mode of the given data set is {}".format(statistics.mode(t)))

Output:

Mode of the given data set is 3 Mode of the given data set is 2

A StatisticsError is raised while using mode when there are two equal modes present in a data set and when the data set is empty or null

Subscribe

Login

Please login to comment

0 Discussion