Advertisement
KillianMills

DataMiningAnalysis1.py

Oct 18th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. #RB = Running Back
  2. #OL = Outside Linebacker
  3. #WR = Wide Receiver
  4. #TE = Tight End
  5. #FB = Full Back
  6. #DB = Defensive Back
  7. #QB = Quarter Back
  8. #LB = Linebacker
  9. #DL = Defensive Lineman
  10.  
  11. def middle(L):
  12.     L = sorted(L)
  13.     n = len(L)
  14.     m = n - 1
  15.     return (L[n/2] + L[m/2]) / 2.0
  16.  
  17. def main():
  18.     masterDict = {} # will only be added to, not reset
  19.     #with open('tester.txt') as f:
  20.     with open('DataSet_DEADNFLPLAYERS.txt') as f:
  21.         for line in f:
  22.             current_line = line.split(',')
  23.             #print current_line
  24.             masterDict.update({len(masterDict) : current_line})
  25.  
  26.     #print masterDict
  27.     total_lifeSpan = 0
  28.     listAges = []
  29.     for key, value in masterDict.items():
  30.         if(key != 0):
  31.  
  32.             deathYear = int(float(value[10].strip())) #10th element
  33.             birthYear = int(float(value[len(value)-1].strip())) #last element
  34.             age = deathYear - birthYear # determines the age at death
  35.             listAges.append(age) # adds age to a list
  36.             total_lifeSpan = total_lifeSpan + age # the combinded age of all players at death
  37.  
  38.     #-------------------------------------------------------------------------
  39.  
  40.     #mean, average age across all players
  41.     print "MEAN"
  42.     average_age = total_lifeSpan / (len(masterDict) -1)
  43.     print average_age
  44.     print "----------"
  45.    
  46.     #mode, the most commonly occuring value
  47.     print "MODE"
  48.     from collections import Counter
  49.     data = Counter(listAges)
  50.     print data.most_common(1)
  51.     print "----------"
  52.  
  53.     #median, the least extreme value or the middle value
  54.     print "MEDIAN"
  55.     print middle(listAges)
  56.     print "----------"
  57.  
  58.  
  59. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement