{"id":25477,"date":"2021-11-16T08:39:21","date_gmt":"2021-11-16T03:09:21","guid":{"rendered":"https:\/\/python-programs.com\/?p=25477"},"modified":"2021-11-16T08:39:21","modified_gmt":"2021-11-16T03:09:21","slug":"python-statistics-median_grouped-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-statistics-median_grouped-method-with-examples\/","title":{"rendered":"Python statistics.median_grouped() Method with Examples"},"content":{"rendered":"
statistics.median_grouped() Method in Python:<\/strong><\/p>\n The statistics.median grouped() method computes the median of grouped continuous data as the 50th percentile.<\/p>\n This method treats the data points as continuous data and computes the 50% percentile median by first determining the median range using the specified interval width (default is 1), and then interpolating within that range using the position of the values from the data set that fall within that range.<\/p>\n GMedian = L + interval * (N \/ 2 – CF) \/ F<\/p>\n is the mathematical formula for Grouped Median.<\/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 interval:<\/strong> This is Optional. The interval between classes. The default value is 1.<\/p>\n Note:<\/strong> It is important to note that if the data is empty, it returns a StatisticsError.<\/p>\n Return Value:<\/strong><\/p>\n Returns a float value that represents the median of grouped continuous data and is calculated as the 50% percentile.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n statistics.median_grouped() 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 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.median_grouped() Method in Python: The statistics.median grouped() method computes the median of grouped continuous data as the 50th percentile. This method treats the data points as continuous data and computes the 50% percentile median by first determining the median range using the specified interval width (default is 1), and then interpolating within that range using …<\/p>\n\n
statistics.median_grouped(data, interval)<\/pre>\n
Given list = [10, 20, 40, 15, 30]<\/pre>\n
The median of grouped continuous data [10, 20, 40, 15, 30] = 20.0<\/pre>\n
Given list = [9, 8, 5, 1]\r\nGiven interval = 3<\/pre>\n
The median of grouped continuous data [9, 8, 5, 1] = 6.5<\/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 = [10, 20, 40, 15, 30]\r\n# Pass the given list as an argument to the statistics.median_grouped() method\r\n# that computes the median of grouped continuous data(given list) as the 50th\r\n# percentile.\r\n# Store it in another variable.\r\nrslt = statistics.median_grouped(gvn_lst)\r\n# Print the median of grouped continuous data(given list) as the 50th percentile.\r\nprint(\"The median of grouped continuous data\", gvn_lst, \"= \", rslt)\r\n<\/pre>\n
The median of grouped continuous data [10, 20, 40, 15, 30] = 20.0<\/pre>\n
With giving interval<\/h5>\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 = [9, 8, 5, 1]\r\n# Give the interval as static input and store it in another variable.\r\ngvn_intrvl = 3\r\n# Pass the given list, interval as the arguments to the statistics.median_grouped()\r\n# method that computes the median of grouped continuous data(given list) as\r\n# the 50th percentile for the given interval width.\r\n# Store it in another variable.\r\nrslt = statistics.median_grouped(gvn_lst, gvn_intrvl)\r\n# Print the median of grouped continuous data(given list) as the 50th percentile.\r\nprint(\"The median of grouped continuous data\", gvn_lst, \"= \", rslt)\r\n<\/pre>\n
The median of grouped continuous data [9, 8, 5, 1] = 6.5<\/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.median_grouped() method\r\n# that computes the median of grouped continuous data(given list) as the 50th\r\n# percentile.\r\n# Store it in another variable.\r\nrslt = statistics.median_grouped(gvn_lst)\r\n# Print the median of grouped continuous data(given list) as the 50th percentile.\r\nprint(\"The median of grouped continuous data\", gvn_lst, \"= \", rslt)\r\n<\/pre>\n
Enter some random List Elements separated by spaces = 5 8 9 4 1\r\nThe median of grouped continuous data [5, 8, 9, 4, 1] = 5.0<\/pre>\n
With giving interval<\/h5>\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# Give the interval as user input using the int(input()) function and store it in another variable.\r\ngvn_intrvl = int(input(\"Enter some random number = \"))\r\n# Pass the given list, interval as the arguments to the statistics.median_grouped()\r\n# method that computes the median of grouped continuous data(given list) as\r\n# the 50th percentile for the given interval width.\r\n# Store it in another variable.\r\nrslt = statistics.median_grouped(gvn_lst, gvn_intrvl)\r\n# Print the median of grouped continuous data(given list) as the 50th percentile.\r\nprint(\"The median of grouped continuous data\", gvn_lst, \"= \", rslt)\r\n\r\n<\/pre>\n
Enter some random List Elements separated by spaces = 4 6 7 2\r\nEnter some random number = 5\r\nThe median of grouped continuous data [4, 6, 7, 2] = 3.5<\/pre>\n","protected":false},"excerpt":{"rendered":"