PyDocs

Nav

Numeric and Mathematical Modules

mode

statistics

function (source)
  • mode(data)
Return the most common data point from discrete or nominal data.

``mode`` assumes discrete data, and returns a single value. This is the
standard treatment of the mode as commonly taught in schools:

    >>> mode([1, 1, 2, 3, 3, 3, 3, 4])
    3

This also works with nominal (non-numeric) data:

    >>> mode(["red", "blue", "blue", "red", "green", "red", "red"])
    'red'

If there are multiple modes with same frequency, return the first one
encountered:

    >>> mode(['red', 'red', 'green', 'blue', 'blue'])
    'red'

If *data* is empty, ``mode``, raises StatisticsError.
Changed in 3.8
  • 3.8: Now handles multimodal datasets by returning the first mode encountered. Formerly, it raised StatisticsError when more than one mode was found.
1 Example
>>> mode([1, 1, 2, 3, 3, 3, 3, 4])
3
from the Python docs
See Also
No see-alsos for statistics/mode
0 Notes
No notes for mode