The Python statistics.mode() function returns the single most common data point from the discrete or nominal data. This function calculates the central tendency from the numerical dataset.
In this function if there are multiple modes with the same frequency, then this function returns the first one in the dataset.
Mode assumes a discrete dataset and returns a single value.
SyntaxFollowing is the basic syntax for the statistics.mode() function −
statistics.mode(data)Parameters
Here, the data values can be used as any sequence, list or iterator.
Return ValueThis function returns the most common first element from the dataset.
Example 1In the below example we are calculating the mode (central tendency) of the given data using statistics.mode() function.
import statistics x = statistics.mode([2, 4, 4, 4, 6, 7, 7, 8]) print(x)Output
This produces the following result −
4Example 2
We are calculating mode for the non-numeric dataset using statistics.mode() function.
import statistics x = statistics.mode(['blue', 'red', 'blue', 'yellow', 'blue', 'red']) print(x)Output
The result produced is as follows −
blueExample 3
Here, we are calculating negative numbers in the dataset using statistics.mode() function.
import statistics x = statistics.mode([-1, 2, -1, 3, -1, -2, -1]) print(x)Output
The output obtained is as follows −
-1
python_modules.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4