# 5 examples of 'how to find median of grouped data' in Python

Every line of 'how to find median of grouped data' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure. ## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``26def median(values):27    length = len(values)28    values.sort()29    if length % 2 != 0:30        # Odd number of values, so chose middle one31        return values[length/2]32    else:33        # Even number of values, so mean of middle two34        return mean([values[length/2], values[(length/2)-1]])``
``106def median(x):107    return sorted(x)[len(x) // 2]``
``136def findMedian(self):137    small, large = self.heaps138    if len(large) > len(small):139        return float(large)140    return (large - small) / 2.0``
``564def _reduce(self, data):565    if not HAS_NUMPY:566        return sorted(data)[len(data) // 2]567568    return np.median(data)``
``42def median(numbers):43   """Return the median of the list of numbers.4445   found at: http://mail.python.org/pipermail/python-list/2004-December/253517.html"""46   # Sort the list and take the middle element.47   n = len(numbers)48   copy = numbers[:] # So that "numbers" keeps its original order49   copy.sort()50   if n & 1:         # There is an odd number of elements51      return copy[n // 2]52   else:53      return (copy[n // 2 - 1] + copy[n // 2]) / 2.0``