Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Fri Apr 6 15:55:29 2018
- @author: cuiha
- """
- class School:
- Name = ""
- Takers = 0
- Read = 0
- Math = 0
- Write = 0
- def getSATtotal(self):
- satTotal = self.Read + self.Math + self.Write
- return satTotal
- def GetMathMindScore(self):
- math_mind = self.Math / max(self.Math, self.Write)
- return math_mind
- import csv
- file = open("2012_SAT_Results.csv")
- reader = csv.reader(file)
- next(reader)
- d = {}
- data = []
- for cols in reader:
- s = School()
- if "s" in cols[2]:
- continue
- s.Name = str(cols[1])
- s.Takers = int(cols[2])
- s.Read = int(cols[3])
- s.Math = int(cols[4])
- s.Write = int(cols[5])
- data.append(s)
- d[s.Name] = s.getSATtotal()
- print("\nFeature 1:")
- import matplotlib.pyplot as plt
- minS = min(data, key = lambda x: x.getSATtotal())
- maxS = max(data, key = lambda x: x.getSATtotal())
- print(str(minS.Name) + " has the minimum score of "+ str(minS.getSATtotal()))
- print(str(maxS.Name) + " has the maximum score of "+ str(maxS.getSATtotal()))
- print("\nFeature 2:")
- def ave(x_list):
- x_list = list(x_list)
- return sum(x_list)/len(x_list)
- takers_group = []
- ave_score = []
- g1 = list(filter(lambda x: x.Takers <= 100, data))
- g2 = list(filter(lambda x: x.Takers > 100 and x.Takers<=200, data))
- g3 = list(filter(lambda x: x.Takers > 200 and x.Takers<=500, data))
- g4 = list(filter(lambda x: x.Takers > 500 and x.Takers<=1000, data))
- g5 = list(filter(lambda x: x.Takers > 1000, data))
- a1 = ave(map(lambda y: y.getSATtotal(),g1))
- a2 = ave(map(lambda y: y.getSATtotal(),g2))
- a3 = ave(map(lambda y: y.getSATtotal(),g3))
- a4 = ave(map(lambda y: y.getSATtotal(),g4))
- a5 = ave(map(lambda y: y.getSATtotal(),g5))
- #print("Average score: # of test takers <= 100 is " + str(a1))
- #print("Average score: # of test takers > 100 and <= 200 is " + str(a2))
- #print("Average score: # of test takers > 200 and <= 500 is " + str(a3))
- #print("Average score: # of test takers > 500 and <= 1000 is " + str(a4))
- #print("Average score: # of test takers > 1000 is " + str(a5))
- x = [0,1,2,3,4]
- y =[a1,a2,a3,a4,a5]
- labels = ["<= 100","<=200","<=500","<=1000",">1000"]
- plt.plot(y)
- plt.xticks(x, labels)
- #plt.margins(0.2)
- #plt.subplots_adjust(bottom=0.15)
- plt.show()
- print("\nFeature 3:")
- print("The top 5 schools that has the highest math_mind are:\n")
- from operator import itemgetter
- for key, value in sorted(d.items(), key = itemgetter(1), reverse = True)[:5]:
- print(key)
- '''
- Best tries:
- mathMind_l = list(map(lambda y: y.getSATtotal(),data))
- sorted_mathMind_l = sorted(mathMind_l, reverse=True)
- sorted_Name = map(lambda y: y.Name,d)
- top5 = sorted_mathMind_l[0:5] # 39
- print(top5)
- print(d)
- #sorted_d = sorted(d.items(), key=operator.itemgetter(1), reverse=True)
- #print(sorted_d)
- result= sorted_d.keys()[0:5]
- #print(sorted_d[0:5])
- print(result)
- '''
Add Comment
Please, Sign In to add comment