def median_grouped(data, interval=1):
 data = sorted(data)
 n = len(data)
 if (n == 0):
  raise StatisticsError('no median for empty data')
 elif (n == 1):
  return data[0]
 x = data[(n // 2)]
 for obj in (x, interval):
  if isinstance(obj, (str, bytes)):
   raise TypeError(('expected number but got %r' % obj))
 try:
  L = (x - (interval / 2))
 except TypeError:
  L = (float(x) - (float(interval) / 2))
 l1 = _find_lteq(data, x)
 l2 = _find_rteq(data, l1, x)
 cf = l1
 f = ((l2 - l1) + 1)
 return (L + ((interval * ((n / 2) - cf)) / f))

def median_grouped ( data , interval = 1 ) : data = sorted ( data ) n = len ( data ) if ( n == 0 ) : raise StatisticsError ( 'no median for empty data' ) elif ( n == 1 ) : return data [ 0 ] x = data [ ( n // 2 ) ] for obj in ( x , interval ) : if isinstance ( obj , ( str , bytes ) ) : raise TypeError ( ( 'expected number but got %r' % obj ) ) try : L = ( x - ( interval / 2 ) ) except TypeError : L = ( float ( x ) - ( float ( interval ) / 2 ) ) l1 = _find_lteq ( data , x ) l2 = _find_rteq ( data , l1 , x ) cf = l1 f = ( ( l2 - l1 ) + 1 ) return ( L + ( ( interval * ( ( n / 2 ) - cf ) ) / f ) )
calculates the grouped mean of the num most recent values .