forked from stanfordjournalism/search-script-scrape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path23.py
21 lines (16 loc) · 774 Bytes
/
23.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# The name of the California school with the highest number of girls enrolled in kindergarten, according to the CA Dept. of Education's latest enrollment data file.
import csv
import requests
from collections import defaultdict
from operator import itemgetter
url = 'http://dq.cde.ca.gov/dataquest/dlfile/dlfile.aspx?cLevel=School&cYear=2014-15&cCat=Enrollment&cPage=filesenr.asp'
def foo(row):
return int(row['KDGN']) if row['KDGN'] else 0
lines = requests.get(url).text.splitlines()
data = list(csv.DictReader(lines, delimiter = "\t"))
codes = defaultdict(int)
for d in data:
if d['GENDER'] == 'F':
codes[d['CDS_CODE']] += int(d['KDGN'])
cds, num = max(codes.items(), key = itemgetter(1))
print([d['SCHOOL'] for d in data if d['CDS_CODE'] == cds][0])