我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用statistics.median_low()。
def MEDIAN_LOW(df, n, price='Close'): """ Low median of data """ median_low_list = [] i = 0 while i < len(df[price]): if i + 1 < n: median_low = float('NaN') else: start = i + 1 - n end = i + 1 median_low = statistics.median_low(df[price][start:end]) median_low_list.append(median_low) i += 1 return median_low_list
def on_peer_response_append(self, peer, msg): """Handle peer response to append_entries. If successful RPC, try to commit new entries. If RPC unsuccessful, backtrack.""" if msg['success']: self.matchIndex[peer] = msg['matchIndex'] self.nextIndex[peer] = msg['matchIndex'] + 1 self.matchIndex[self.volatile['address']] = self.log.index self.nextIndex[self.volatile['address']] = self.log.index + 1 index = statistics.median_low(self.matchIndex.values()) self.log.commit(index) self.send_client_append_response() else: self.nextIndex[peer] = max(0, self.nextIndex[peer] - 1)
def main(): print(stats.mean(range(6))) print(stats.median(range(6))) print(stats.median_low(range(6))) print(stats.median_high(range(6))) print(stats.median_grouped(range(6))) try: print(stats.mode(range(6))) except Exception as e: print(e) print(stats.mode(list(range(6)) + [3])) print(stats.pstdev(list(range(6)) + [3])) print(stats.stdev(list(range(6)) + [3])) print(stats.pvariance(list(range(6)) + [3])) print(stats.variance(list(range(6)) + [3]))
def test_even_ints(self): # Test median_low with an even number of ints. data = [1, 2, 3, 4, 5, 6] assert len(data)%2 == 0 self.assertEqual(self.func(data), 3)
def test_even_fractions(self): # Test median_low works with an even number of Fractions. F = Fraction data = [F(1, 7), F(2, 7), F(3, 7), F(4, 7), F(5, 7), F(6, 7)] assert len(data)%2 == 0 random.shuffle(data) self.assertEqual(self.func(data), F(3, 7))
def test_even_decimals(self): # Test median_low works with an even number of Decimals. D = Decimal data = [D('1.1'), D('2.2'), D('3.3'), D('4.4'), D('5.5'), D('6.6')] assert len(data)%2 == 0 random.shuffle(data) self.assertEqual(self.func(data), D('3.3'))
def sortSubListsAndMedian(A): sortedList = [] medianList = [] for smallList in A: sortedList.append(sorted(smallList)) medianList.append(statistics.median_low(smallList)) return sortedList, medianList
def median_low(text): """ Finds the low median of a space-separated list of numbers. Example:: /median low 33 54 43 65 43 62 """ return format_output(statistics.median_low(parse_numeric_list(text)))
def setup(): commands.add(mean) commands.add(median) commands.add(median_low) commands.add(median_high) commands.add(median_grouped) commands.add(mode) commands.add(pstdev) commands.add(pvariance) commands.add(stdev) commands.add(variance)