コード例 #1
0
def summary_stats(data_list):
    """
    Accepts a sample of numbers and returns a pretty
    print out of a variety of descriptive statistics.
    """
    mean = calculate.mean(data_list)
    median = calculate.median(data_list)
    mode = calculate.mode(data_list)
    n = len(data_list)
    max_ = max(data_list)
    min_ = min(data_list)
    range_ = calculate.range(data_list)
    standard_deviation = calculate.standard_deviation(data_list)
    
    print """
Summary statistics
==================

n:        %s
max:        %s
min:        %s
range:        %s
mean:        %s
median:        %s
mode:        %s
std:        %s
""" % (n, max_, min_, range_, mean, median, mode, standard_deviation)
コード例 #2
0
def summary_stats(data_list):
    """
    Accepts a sample of numbers and returns a pretty
    print out of a variety of descriptive statistics.
    """
    mean = calculate.mean(data_list)
    median = calculate.median(data_list)
    mode = calculate.mode(data_list)
    n = len(data_list)
    max_ = max(data_list)
    min_ = min(data_list)
    range_ = calculate.range(data_list)
    standard_deviation = calculate.standard_deviation(data_list)
    variation_coefficient = calculate.variation_coefficient(data_list)

    table = ptable.indent(
        [
            ['Statistic', 'Value'],
            ['n', str(n)],
            ['mean', str(mean)],
            ['median', str(median)],
            ['mode', str(mode)],
            ['maximum', str(max_)],
            ['minimum', str(min_)],
            ['range', str(range_)],
            ['standard deviation', str(standard_deviation)],
            ['variation coefficient', str(variation_coefficient)],
        ],
        hasHeader=True,
        separateRows=False,
        prefix="| ", postfix=" |",
    )
    print(table)
コード例 #3
0
 def test_range(self):
     self.assertEqual(calculate.range([1, 2, 3]), 2)
     self.assertRaises(ValueError, calculate.range, ['a', 1, 2])
     self.assertRaises(ValueError, calculate.range, [1])
コード例 #4
0
 def test_range(self):
     self.assertEqual(calculate.range([1, 2, 3]), 2)
     self.assertRaises(ValueError, calculate.range, ['a', 1, 2])
     self.assertRaises(ValueError, calculate.range, [1])
コード例 #5
0
 def test_range(self):
     self.assertEqual(calculate.range([1,2,3]), 2)
     with self.assertRaises(ValueError):
         calculate.range(['a', 1, 2])