def summarize(csv_path: str) -> OrderedDict: """ Summarize a CSV file of feature values. Parameters ---------- csv_path : str Path to csv. Returns ------- OrderedDict Summary values. """ with open(csv_path) as infile: reader = csv.reader(infile) table = [row for row in reader] d = OrderedDict() ignored_cols = 2 d['datapoints'] = len(table) - 1 for i, col in enumerate(table[0][ignored_cols:]): i += ignored_cols d[col] = labmath.mean([float(r[i]) for r in table[1:]]) return d
def test_mean_single_item_array(): assert 1 == labmath.mean([1])
def test_mean(): assert 2 == labmath.mean([1, 2, 3]) assert (1 / 3.) == labmath.mean([1, 1.5, -1.5]) assert 2 == labmath.mean([2, 2, 2, 2, 2]) assert 2.5 == labmath.mean([1, 2, 3, 4])
def test_mean_empty_array(): assert 0 == labmath.mean([])