What is statistics.multimode() in Python?
Overview
The multimode() method is used to get a list of the most commonly occurring data values (the mode). If there are values with the same frequency, then the values are returned in the order of their occurrence.
The method returns an empty list if no data is supplied to the function.
Syntax
multimode(data)
Parameters
data: The population from whichmultimodehas to be extracted.
Return value
The method returns a list of the most occurring values in the given data.
Code example 1
import statisticsdata = "wefhbgssaklvgggggbvfjn bvdnesdccdsss"print("Multimode - ", statistics.multimode(data))
Explanation
- Line 1: We load the
statisticsmodule in our program. - Line 3: We define a string called
data. - Line 5: We compute the most frequently occurring characters using the
multimode()function.
Code example 2
import statisticsdata = [2, 3, 4, 2, 3, 2, 1, 6, 8, 3, 2, 4, 2, 3, 3]print("Multimode - ", statistics.multimode(data))
Explanation
- Line 1: We load the
statisticsmodule in our program. - Line 3: We define a list of integers called
data. - Line 5: We compute the most frequently occurring integers using the
multimode()function.