Python statistics.median_grouped() Examples
The following are 22
code examples of statistics.median_grouped().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
statistics
, or try the search function
.
Example #1
Source File: test_statistics.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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))
Example #2
Source File: test_statistics.py From android_universal with MIT License | 5 votes |
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)
Example #3
Source File: test_statistics.py From android_universal with MIT License | 5 votes |
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)
Example #4
Source File: test_statistics.py From android_universal with MIT License | 5 votes |
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)
Example #5
Source File: test_statistics.py From android_universal with MIT License | 5 votes |
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)
Example #6
Source File: test_statistics.py From android_universal with MIT License | 5 votes |
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)
Example #7
Source File: test_statistics.py From android_universal with MIT License | 5 votes |
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))
Example #8
Source File: test_statistics.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #9
Source File: test_statistics.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #10
Source File: test_statistics.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #11
Source File: test_statistics.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #12
Source File: test_statistics.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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))
Example #13
Source File: statistic_functions.py From jhTAlib with GNU General Public License v3.0 | 5 votes |
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
Example #14
Source File: test_statistics.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #15
Source File: test_statistics.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #16
Source File: test_statistics.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #17
Source File: test_statistics.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #18
Source File: test_statistics.py From ironpython3 with Apache License 2.0 | 5 votes |
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))
Example #19
Source File: test_statistics.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #20
Source File: test_statistics.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #21
Source File: test_statistics.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #22
Source File: test_statistics.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)