當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。