{"id":25461,"date":"2021-11-16T08:39:29","date_gmt":"2021-11-16T03:09:29","guid":{"rendered":"https:\/\/python-programs.com\/?p=25461"},"modified":"2021-11-16T08:39:29","modified_gmt":"2021-11-16T03:09:29","slug":"python-statistics-mode-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-statistics-mode-method-with-examples\/","title":{"rendered":"Python statistics.mode() Method with Examples"},"content":{"rendered":"
statistics.mode() Method in Python:<\/strong><\/p>\n Statistics.mode() computes the mode (central tendency) of a numeric or nominal data set.<\/p>\n The mode of a set of data values is the most frequently occurring value. It is the most likely value at which the data will be sampled. A mode of a continuous probability distribution is frequently defined as any value x at which its probability density function has a local maximum value, implying that any peak is a mode.<\/p>\n Syntax:<\/strong><\/p>\n Parameters<\/strong><\/p>\n data:<\/strong> This is Required. It is the data values that will be used (it can be any sequence, list, or iterator).<\/p>\n Note:<\/strong> It is to be noted that if the data is empty, it returns a StatisticsError.<\/p>\n Return Value:<\/strong><\/p>\n Returns a float or nominal value that represents the given data’s mode.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explanation:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n statistics.mode() Method with Examples in Python<\/span><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n statistics.mode() Method in Python: Statistics.mode() computes the mode (central tendency) of a numeric or nominal data set. The mode of a set of data values is the most frequently occurring value. It is the most likely value at which the data will be sampled. A mode of a continuous probability distribution is frequently defined as …<\/p>\nstatistics.mode(data)<\/pre>\n
Given list = ['hello', 'this', 'is', 'btechgeeks', 'hello']<\/pre>\n
The mode of the given list items ['hello', 'this', 'is', 'btechgeeks', 'hello'] = hello<\/pre>\n
Here 'hello' occurs most frequently. Hence the mode is 'hello'.<\/pre>\n
Given list = [3, 4, 2, 5, 6, 3, 3, 1, 3]<\/pre>\n
The mode of the given list items [3, 4, 2, 5, 6, 3, 3, 1, 3] = 3<\/pre>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import statistics module using the import keyword.\r\nimport statistics\r\n# Give the list as static input and store it in a variable.\r\ngvn_lst = ['hello', 'this', 'is', 'btechgeeks', 'hello']\r\n# Pass the given list as an argument to the statistics.mode() method that\r\n# computes the mode (which occurs most frequently) of the given list items.\r\n# Store it in another variable.\r\nrslt = statistics.mode(gvn_lst)\r\n# Print the mode of the given list items.\r\nprint(\"The mode of the given list items\", gvn_lst, \"= \", rslt)\r\n<\/pre>\n
The mode of the given list items ['hello', 'this', 'is', 'btechgeeks', 'hello'] = hello<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import statistics module using the import keyword.\r\nimport statistics\r\n# Give the list as user input using list(),map(),input(),and split() functions.\r\n# Store it in a variable.\r\ngvn_lst = list(map(int, input(\r\n 'Enter some random List Elements separated by spaces = ').split()))\r\n\r\n# Pass the given list as an argument to the statistics.mode() method that\r\n# computes the mode (which occurs most frequently) of the given list items.\r\n# Store it in another variable.\r\nrslt = statistics.mode(gvn_lst)\r\n# Print the mode of the given list items.\r\nprint(\"The mode of the given list items\", gvn_lst, \"= \", rslt)\r\n<\/pre>\n
Enter some random List Elements separated by spaces = 3 4 2 5 6 3 3 1 3\r\nThe mode of the given list items [3, 4, 2, 5, 6, 3, 3, 1, 3] = 3<\/pre>\n","protected":false},"excerpt":{"rendered":"