Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #RB = Running Back
- #OL = Outside Linebacker
- #WR = Wide Receiver
- #TE = Tight End
- #FB = Full Back **************** merged with RB
- #DB = Defensive Back
- #QB = Quarter Back
- #LB = Linebacker
- #DL = Defensive Lineman
- def middle(L):
- L = sorted(L)
- n = len(L)
- m = n - 1
- return (L[n/2] + L[m/2]) / 2.0
- def main():
- masterDict = {} # will only be added to, not reset
- #with open('tester.txt') as f:
- with open('DataSet_DEADNFLPLAYERS.txt') as f:
- for line in f:
- current_line = line.split(',')
- masterDict.update({len(masterDict) : current_line})
- #print masterDict
- total_lifeSpan = 0 # will hold total lifespan of all players
- listAges = [] # will hold a list of all player's ages
- # lists for ages of each role
- fullBackAges = []
- #runningBackAges = [] # full back and runningBack are the same in our dataset
- outsideLineBackerAges = []
- wideReceiverAges = []
- tightEndAges = []
- defensiveBackAges = []
- quarterBackAges = []
- lineBackerAges = []
- defensiveLinemanAges = []
- cleanedUpAges = []
- modernAges = []
- for key, value in masterDict.items():
- if(key != 0):
- deathYear = int(float(value[10].strip())) #10th element
- birthYear = int(float(value[len(value)-1].strip())) #last element
- age = deathYear - birthYear # determines the age at death
- listAges.append(age) # adds age to a list
- total_lifeSpan = total_lifeSpan + age # the combinded age of all players at death
- if "FB" in value[8]:
- fullBackAges.append(age)
- #elif "RB" in value[8]: # full back and runningBack are the same in our dataset
- #runningBackAges.append(age)
- elif "OL" in value[8]:
- outsideLineBackerAges.append(age)
- elif "WR" in value[8]:
- wideReceiverAges.append(age)
- elif "TE" in value[8]:
- tightEndAges.append(age)
- elif "DB" in value[8]:
- defensiveBackAges.append(age)
- elif "QB" in value[8]:
- quarterBackAges.append(age)
- elif "LB" in value[8]:
- lineBackerAges.append(age)
- elif "DL" in value[8]:
- defensiveLinemanAges.append(age)
- if((age < 80) and (age > 50)):
- cleanedUpAges.append(age)
- if birthYear >= 1940:
- modernAges.append(age)
- #---------------------------FOR ALL ROLES----------------------------------
- #mean, average age across all players
- #print "MEAN OF ALL"
- average_age = total_lifeSpan / (len(masterDict) -1)
- #print average_age
- #print "----------"
- #mode, the most commonly occuring value
- #print "MODE OF ALL"
- from collections import Counter
- data = Counter(listAges)
- modeData = data.most_common(1)
- newModeData = [x[0] for x in modeData]
- #print data.most_common(1)
- #print "----------"
- #median, the least extreme value or the middle value
- #print "MEDIAN OF ALL"
- #print middle(listAges)
- #print "----------"
- #mid-range, the mean of the highest and lowest value
- #print "MIDRANGE OF ALL"
- midrange = min(listAges) + max(listAges)
- midrange = midrange / 2
- #print midrange
- #print "----------"
- #print "----------"
- #print "----------"
- #print newModeData
- #newMode = (3 * midrange) - (2 * newModeData[0])
- newMode = (3 * middle(listAges)) - ( 2 * average_age)
- print "MEAN OF ALL"
- print newMode
- print "MEDIAN OF ALL"
- newMedian = newModeData[0] + (2 * (average_age - newModeData[0]) / 3)
- print newMedian
- print "MEAN - MODE"
- newValue = average_age - newModeData[0]
- print newValue
- #-------------------------FOR THE NINE ROLES-----------------------------
- printingList = []
- printingList.append(fullBackAges)
- #printingList.append(runningBackAges)# full back and runningBack are the same in our dataset
- printingList.append(outsideLineBackerAges)
- printingList.append(wideReceiverAges)
- printingList.append(tightEndAges)
- printingList.append(defensiveBackAges)
- printingList.append(quarterBackAges)
- printingList.append(lineBackerAges)
- printingList.append(defensiveLinemanAges)
- printingList.append(cleanedUpAges)
- printingList.append(modernAges)
- for playerList in printingList:
- #mean, average age across all players
- #print ("MEAN OF ")#, playerList)
- average_age = sum(playerList) / (len(playerList) -1)
- #print average_age
- #print "----------"
- #mode, the most commonly occuring value
- #print ("MODE OF ")# % playerList)
- from collections import Counter
- data = Counter(playerList)
- #print data.most_common(1)
- #print "----------"
- #median, the least extreme value or the middle value
- #print ("MEDIAN OF)# " % playerList)
- #print middle(playerList)
- #print "----------"
- #mid-range, the mean of the highest and lowest value
- #print ("MIDRANGE OF ")# % playerList
- midrange = min(playerList) + max(playerList)
- midrange = midrange / 2
- #print midrange
- #print "----------"
- #print "----------"
- #print "----------"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement