Skip to content

Instantly share code, notes, and snippets.

@linwoodc3
Created January 31, 2015 20:10
Show Gist options
  • Save linwoodc3/ca76f3ad7f6a8ec8a02b to your computer and use it in GitHub Desktop.
Save linwoodc3/ca76f3ad7f6a8ec8a02b to your computer and use it in GitHub Desktop.
This summarizes the salary of NBA players. Eventually, I will compare the salary to the player efficiency rating.
__author__ = 'Linwood Creekmore'
## Wrote this for Software Engineering for Data Class ##
## My first solo creation
import csv
f = open('nba_players.csv')
csv_f = csv.reader(f)
lst = []
lst2 = []
for row in csv_f:
lst.append(row[18])
lst2.append(row[12])
#print row
print lst2
per = lst2[1:]
new_list = lst[1:]
per = map(float, per)
new_list = map(int, new_list)
print per
half = len(new_list) / 2
per.sort()
new_list.sort()
if len(new_list) % 2 == 0:
print "The median NBA salary is $%r " % (new_list[half - 1] + new_list[half]) / 2.0
else:
print "The median NBA salary is $%r " % new_list[half]
weird = len(new_list)
mean = sum(new_list) / weird
from collections import Counter
data = Counter(new_list)
data.most_common() # Returns all unique items and their counts
print "The mode is $ %r " % data.most_common(1) # Returns the highest occurring item
print "The minimum NBA salary is $%r ." % min(new_list)
print "The maximum NBA salary is $%r . " % max(new_list)
print "The mean or average NBA salary is $%r !. Wow, that's a lot of money" % mean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment