Full name
statistics.mode
Library
statistics
Syntax
statistics.mode(data)
Description
The statistics.mode function returns the most frequent value (the mode) of data. If there is more than one value with the same frequency, the first one found in data is returned.
If the structure data is empty, the function returns an error.
Parameters
- data: Structure from which to extract the most frequent value. It can be made up of numbers or values of other types.
Result
The statistics.mode function returns the most frequent value found in data, regardless of its type.
Examples
We can extract the most frequent value from a list of numbers with the following code:
statistics.mode([1, 4, 3, 6, 4, 8])
4
The values in data can be of any type:
statistics.mode([1, "a", 4, 3, 6, 4, 8, "a", 5, "a"])
'a'
If we apply this function to a text string, it returns the most frequent character:
statistics.mode("data science")
'a'