-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathexample.py
More file actions
executable file
·40 lines (25 loc) · 898 Bytes
/
Copy pathexample.py
File metadata and controls
executable file
·40 lines (25 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
import csv
import proof
def load_data(data):
# Load the data
with open('example.csv') as f:
reader = csv.DictReader(f, fieldnames=['name', 'salary'])
next(reader)
data['table'] = list(reader)
def filter_rows(row):
return int(row['salary']) < 25000
def select_rows(data):
# Select relevant rows from the table
data['low_income'] = list(filter(filter_rows, data['table']))
def calculate_average(data):
# The average of a value in the rows is taken
data['mean'] = sum([int(r['salary']) for r in data['low_income']]) / len(data['low_income'])
@proof.never_cache
def print_results(data):
print(data['mean'])
data_loaded = proof.Analysis(load_data)
rows_selected = data_loaded.then(select_rows)
average_calculated = rows_selected.then(calculate_average)
average_calculated.then(print_results)
data_loaded.run()