Guest User

Untitled

a guest
Apr 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Fri Apr 6 15:55:29 2018
  4.  
  5. @author: cuiha
  6. """
  7. class School:
  8. Name = ""
  9. Takers = 0
  10. Read = 0
  11. Math = 0
  12. Write = 0
  13.  
  14. def getSATtotal(self):
  15. satTotal = self.Read + self.Math + self.Write
  16. return satTotal
  17.  
  18. def GetMathMindScore(self):
  19. math_mind = self.Math / max(self.Math, self.Write)
  20. return math_mind
  21.  
  22. import csv
  23. file = open("2012_SAT_Results.csv")
  24. reader = csv.reader(file)
  25. next(reader)
  26. d = {}
  27. data = []
  28. for cols in reader:
  29. s = School()
  30. if "s" in cols[2]:
  31. continue
  32. s.Name = str(cols[1])
  33. s.Takers = int(cols[2])
  34. s.Read = int(cols[3])
  35. s.Math = int(cols[4])
  36. s.Write = int(cols[5])
  37. data.append(s)
  38. d[s.Name] = s.getSATtotal()
  39.  
  40. print("\nFeature 1:")
  41. import matplotlib.pyplot as plt
  42. minS = min(data, key = lambda x: x.getSATtotal())
  43. maxS = max(data, key = lambda x: x.getSATtotal())
  44. print(str(minS.Name) + " has the minimum score of "+ str(minS.getSATtotal()))
  45. print(str(maxS.Name) + " has the maximum score of "+ str(maxS.getSATtotal()))
  46.  
  47. print("\nFeature 2:")
  48. def ave(x_list):
  49. x_list = list(x_list)
  50. return sum(x_list)/len(x_list)
  51.  
  52. takers_group = []
  53. ave_score = []
  54. g1 = list(filter(lambda x: x.Takers <= 100, data))
  55. g2 = list(filter(lambda x: x.Takers > 100 and x.Takers<=200, data))
  56. g3 = list(filter(lambda x: x.Takers > 200 and x.Takers<=500, data))
  57. g4 = list(filter(lambda x: x.Takers > 500 and x.Takers<=1000, data))
  58. g5 = list(filter(lambda x: x.Takers > 1000, data))
  59. a1 = ave(map(lambda y: y.getSATtotal(),g1))
  60. a2 = ave(map(lambda y: y.getSATtotal(),g2))
  61. a3 = ave(map(lambda y: y.getSATtotal(),g3))
  62. a4 = ave(map(lambda y: y.getSATtotal(),g4))
  63. a5 = ave(map(lambda y: y.getSATtotal(),g5))
  64. #print("Average score: # of test takers <= 100 is " + str(a1))
  65. #print("Average score: # of test takers > 100 and <= 200 is " + str(a2))
  66. #print("Average score: # of test takers > 200 and <= 500 is " + str(a3))
  67. #print("Average score: # of test takers > 500 and <= 1000 is " + str(a4))
  68. #print("Average score: # of test takers > 1000 is " + str(a5))
  69.  
  70. x = [0,1,2,3,4]
  71. y =[a1,a2,a3,a4,a5]
  72. labels = ["<= 100","<=200","<=500","<=1000",">1000"]
  73. plt.plot(y)
  74. plt.xticks(x, labels)
  75. #plt.margins(0.2)
  76. #plt.subplots_adjust(bottom=0.15)
  77. plt.show()
  78.  
  79. print("\nFeature 3:")
  80. print("The top 5 schools that has the highest math_mind are:\n")
  81.  
  82. from operator import itemgetter
  83. for key, value in sorted(d.items(), key = itemgetter(1), reverse = True)[:5]:
  84. print(key)
  85. '''
  86. Best tries:
  87. mathMind_l = list(map(lambda y: y.getSATtotal(),data))
  88. sorted_mathMind_l = sorted(mathMind_l, reverse=True)
  89. sorted_Name = map(lambda y: y.Name,d)
  90. top5 = sorted_mathMind_l[0:5] # 39
  91. print(top5)
  92.  
  93. print(d)
  94.  
  95.  
  96. #sorted_d = sorted(d.items(), key=operator.itemgetter(1), reverse=True)
  97. #print(sorted_d)
  98.  
  99. result= sorted_d.keys()[0:5]
  100. #print(sorted_d[0:5])
  101. print(result)
  102. '''
Add Comment
Please, Sign In to add comment