This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
In this article, you will learn how to calculate the mode of a list in Python.
Let’s say you have a list named ‘a’ with value [1, 2, 1, 3, 2, 2, 1, 3, 4].
a = [1, 2, 1, 3, 2, 2, 1, 3, 4]
In order to calculate the mode of a list, you can use the statistics.mode()
method.
# Import statistics module
import statistics
a = [1, 2, 1, 3, 2, 2, 1, 3, 4]
print(statistics.mode(a))
# => 1
Note: The statistics.mode()
method functions by returning the mode of a supplied list. In statistics, mode
refers to a value that appears the most often in a set of values.
The post How to Calculate Mode of List in Python appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
Ariessa Norramli | Sciencx (2021-02-23T13:20:28+00:00) How to Calculate Mode of List in Python. Retrieved from https://www.scien.cx/2021/02/23/how-to-calculate-mode-of-list-in-python/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.