-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnfl.py
31 lines (26 loc) · 902 Bytes
/
nfl.py
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
# Utilities
import csv
import numpy as np
from collections import namedtuple
from collections import defaultdict
from collections import Counter
def loadData():
PlayerTeam = namedtuple('PlayerTeam','teamname playername')
PlayerCollege = namedtuple('PlayerCollege', 'playername collegename')
teams = []
for line in csv.reader(open("playerteam.csv", "rb"), delimiter='\t'):
p = PlayerTeam._make(line)
teams.append(p)
colleges = []
for line in csv.reader(open("playercollege.csv", "rb"), delimiter='\t'):
p = PlayerCollege._make(line)
colleges.append(p)
return teams, colleges
def partitionTable(table, hashfunction,buckets):
hRes = defaultdict(list)
for b in range(buckets):
hRes[b] = []
attribute = 'playername'
for s in table:
hRes[hashfunction(getattr(s, attribute),buckets)].append(s)
return hRes