当前位置: 首页>>代码示例>>Python>>正文


Python statistics.median_grouped方法代码示例

本文整理汇总了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)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_statistics.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_statistics.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_statistics.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_statistics.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_statistics.py

示例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 
开发者ID:joosthoeks,项目名称:jhTAlib,代码行数:29,代码来源:statistic_functions.py

示例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) 
开发者ID:bkerler,项目名称:android_universal,代码行数:17,代码来源:test_statistics.py


注:本文中的statistics.median_grouped方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。