|
1 scores = [[], [], [], [], []] |
|
2 ninety_percents = [{}, {}, {}, {}, {}] |
|
3 |
|
4 for record in open('sslc1.txt'): |
|
5 record = record.strip() |
|
6 fields = record.split(';') |
|
7 |
|
8 region_code = fields[0].strip() |
|
9 |
|
10 for i, field in enumerate(fields[3:8]): |
|
11 if region_code not in ninety_percents[i]: |
|
12 ninety_percents[i][region_code] = 0 |
|
13 score_str = field.strip() |
|
14 score = 0 if score_str == 'AA' else int(score_str) |
|
15 scores[i].append(score) |
|
16 if score > 90: |
|
17 ninety_percents[i][region_code] += 1 |
|
18 |
|
19 subj_total = [] |
|
20 for subject in ninety_percents: |
|
21 subj_total.append(sum(subject.values())) |
|
22 |
|
23 |
|
24 figure(1) |
|
25 pie(ninety_percents[3].values(), labels=ninety_percents[3].keys()) |
|
26 title('Students scoring 90% and above in science by region') |
|
27 savefig('science.png') |
|
28 |
|
29 figure(2) |
|
30 pie(subj_total, labels=['English', 'Hindi', 'Maths', 'Science', 'Social']) |
|
31 title('Students scoring more than 90% by subject(All regions combined).') |
|
32 savefig('all_regions.png') |
|
33 |
|
34 # List method |
|
35 print "Mean: ", mean(scores[2]) |
|
36 |
|
37 print "Median: ", median(scores[2]) |
|
38 |
|
39 print "Standard Deviation: ", std(scores[2]) |
|
40 |
|
41 # Array method |
|
42 |
|
43 #math_scores = array(scores[2]) |
|
44 |
|
45 #print "Mean: ", mean(math_scores) |
|
46 |
|
47 #print "Median: ", median(math_scores) |
|
48 |
|
49 #print "Standard Deviation: ", std(math_scores) |
|
50 |