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