Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON Who was the best NBA basketball player? The NBA is North America’s profes

ID: 3811736 • Letter: P

Question

PYTHON Who was the best NBA basketball player? The NBA is North America’s professional men’s basketball league. You are going to write a program to find the best players in NBA history. Using the csv file provided with the lab. Calculate the efficiency for each player, using the csv file provided with the lab. NBA player’s performance is evaluated using the following efficiency formula. Efficiency = ( ( pts + reb + asts + stl + blk ) - ( ( fga – fgm ) + ( fta – ftm ) + turnover ) ) / gp

1. Find the top 50 players with the best efficiency results and Display those 50 from best to worst.

2. Find and display the Player who played the most minutes

3. Find and display the player who play the most games

4. Find and display the Player who scored the most points

5. Find and display the Player who got the most penalties.

6. Find and display the Player who made the most free throws.

Please avoid using pandas, as I do not have that, nor are we allowed to use it. Thanks.

Here is a sample from the file:

ilkid,year,firstname,lastname,team,leag,gp,minutes,pts,oreb,dreb,reb,asts,stl,blk,turnover,pf,fga,fgm,fta,ftm,tpa,tpm

ABRAMJO01 ,1946,John,Abramovic,PIT,N,47,0,527,0,0,0,35,0,0,0,161,834,202,178,123,0,0

AUBUCCH01 ,1946,Chet,Aubuchon,DE1,N,30,0,65,0,0,0,20,0,0,0,46,91,23,35,19,0,0

BAKERNO01 ,1946,Norm,Baker,CH1,N,4,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0

BALTIHE01 ,1946,Herschel,Baltimore,ST1,N,58,0,138,0,0,0,16,0,0,0,98,263,53,69,32,0,0

BARRJO01 ,1946,John,Barr,ST1,N,58,0,295,0,0,0,54,0,0,0,164,438,124,79,47,0,0

BAUMHFR01 ,1946,Frankie,Baumholtz,CL1,N,45,0,631,0,0,0,54,0,0,0,93,856,255,156,121,0,0

BECKEMO01 ,1946,Moe,Becker,BOS,N,6,0,13,0,0,0,1,0,0,0,15,22,5,4,3,0,0

BECKEMO01 ,1946,Moe,Becker,DE1,N,20,0,41,0,0,0,15,0,0,0,33,107,19,10,3,0,0

BECKEMO01 ,1946,Moe,Becker,PIT,N,17,0,108,0,0,0,14,0,0,0,50,229,46,30,16,0,0

BECKEMO01 ,1946,Moe,Becker,TOT,N,43,0,162,0,0,0,30,0,0,0,98,358,70,44,22,0,0

BEENDHA01 ,1946,Hank,Beenders,PRO,N,58,0,713,0,0,0,37,0,0,0,196,1016,266,257,181,0,0

BIASAHA01 ,1946,Hank,Biasatti,TOR,N,6,0,6,0,0,0,0,0,0,0,3,5,2,4,2,0,0

BRIGHAL01 ,1946,Al,Brightman,BOS,N,58,0,567,0,0,0,60,0,0,0,115,870,223,193,121,0,0

Explanation / Answer

The code is given in python as following :

import csv
#for importing csv files
file_name='Users/Keerthi/Documents/sample.csv'
with open ('C:/Users/Keerthi/Desktop/in.csv') as csvfile:
reader = csv.DictReader(csvfile)
P_M=""
P_E=""
P_G=""
P_G=""
P_F=""
min_P=0
thrpt=0
gme_Pl=0
score=0
freeThrows=0
#each row of the csv
for row in reader:
mp=int(row['minutes'])
if(mp>min_P):
min_P=mp
P_M=row['firstname']+row['lastname']
gg=int(row['gp'])
if(gg>gme_Pl):
gme_Pl=gg
P_G=row['firstname']+row['lastname']
pt=int(row['pts'])
if(pt>score):
score=pt
P_G=row['firstname']+row['lastname']
ft=int(row['fta'])
if(ft>freeThrows):
freeThrows=ft
P_F=row['firstname']+row['lastname']
E=int(rowr['pts'])+int(row['reb'])+int(row['asts'])+int(row['stl'])+int(row['blk'])

E=E-(int(row['fga'])-int(row['fgm'])+int(row['fta'])-int(row['ftm'])+int(row['turnover']))
E=E/int(row['gp'])
if(E>thrpt):
thrpt=E;
print("most minutes played players", P_M, "is", min_P)
print("efficient player", P_E, "is", thrpt)
print("most games played", P_G, "is", gme_Pl)
print("most points", P_G, "is", score)
print("Pmost free throws", P_F, "is", freeThrows)