本文整理汇总了Python中statistics.median_grouped方法的典型用法代码示例。如果您正苦于以下问题:Python statistics.median_grouped方法的具体用法?Python statistics.median_grouped怎么用?Python statistics.median_grouped使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statistics
的用法示例。
在下文中一共展示了statistics.median_grouped方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_repeated_single_value
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import median_grouped [as 别名]
def test_repeated_single_value(self):
# Override method from AverageMixin.
# Yet again, failure of median_grouped to conserve the data type
# causes me headaches :-(
for x in (5.3, 68, 4.3e17, Fraction(29, 101), Decimal('32.9714')):
for count in (2, 5, 10, 20):
data = [x]*count
self.assertEqual(self.func(data), float(x))
示例2: test_odd_fractions
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import median_grouped [as 别名]
def test_odd_fractions(self):
# Test median_grouped works with an odd number of Fractions.
F = Fraction
data = [F(5, 4), F(9, 4), F(13, 4), F(13, 4), F(17, 4)]
assert len(data)%2 == 1
random.shuffle(data)
self.assertEqual(self.func(data), 3.0)
示例3: test_even_fractions
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import median_grouped [as 别名]
def test_even_fractions(self):
# Test median_grouped works with an even number of Fractions.
F = Fraction
data = [F(5, 4), F(9, 4), F(13, 4), F(13, 4), F(17, 4), F(17, 4)]
assert len(data)%2 == 0
random.shuffle(data)
self.assertEqual(self.func(data), 3.25)
示例4: test_odd_decimals
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import median_grouped [as 别名]
def test_odd_decimals(self):
# Test median_grouped works with an odd number of Decimals.
D = Decimal
data = [D('5.5'), D('6.5'), D('6.5'), D('7.5'), D('8.5')]
assert len(data)%2 == 1
random.shuffle(data)
self.assertEqual(self.func(data), 6.75)
示例5: test_even_decimals
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import median_grouped [as 别名]
def test_even_decimals(self):
# Test median_grouped works with an even number of Decimals.
D = Decimal
data = [D('5.5'), D('5.5'), D('6.5'), D('6.5'), D('7.5'), D('8.5')]
assert len(data)%2 == 0
random.shuffle(data)
self.assertEqual(self.func(data), 6.5)
#---
data = [D('5.5'), D('5.5'), D('6.5'), D('7.5'), D('7.5'), D('8.5')]
assert len(data)%2 == 0
random.shuffle(data)
self.assertEqual(self.func(data), 7.0)
示例6: MEDIAN_GROUPED
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import median_grouped [as 别名]
def MEDIAN_GROUPED(df, n, price='Close', interval=1):
"""
Median, or 50th percentile, of grouped data
Returns: list of floats = jhta.MEDIAN_GROUPED(df, n, price='Close', interval=1)
"""
median_grouped_list = []
if n == len(df[price]):
start = None
for i in range(len(df[price])):
if df[price][i] != df[price][i]:
median_grouped = float('NaN')
else:
if start is None:
start = i
end = i + 1
median_grouped = statistics.median_grouped(df[price][start:end], interval)
median_grouped_list.append(median_grouped)
else:
for i in range(len(df[price])):
if i + 1 < n:
median_grouped = float('NaN')
else:
start = i + 1 - n
end = i + 1
median_grouped = statistics.median_grouped(df[price][start:end], interval)
median_grouped_list.append(median_grouped)
return median_grouped_list
示例7: test_data_type_error
# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import median_grouped [as 别名]
def test_data_type_error(self):
# Test median_grouped with str, bytes data types for data and interval
data = ["", "", ""]
self.assertRaises(TypeError, self.func, data)
#---
data = [b"", b"", b""]
self.assertRaises(TypeError, self.func, data)
#---
data = [1, 2, 3]
interval = ""
self.assertRaises(TypeError, self.func, data, interval)
#---
data = [1, 2, 3]
interval = b""
self.assertRaises(TypeError, self.func, data, interval)