Please help me about this python coding problem. The data file \"NBA.csv\" conta
ID: 3872192 • Letter: P
Question
Please help me about this python coding problem.
The data file "NBA.csv" contains information on 2763 NBA players from their rookie season. The data contain seven attributes: ID, FN, LN, isAllStar, DRAFT_YR, MPG, PPG. Make sure that "NBA.csv" is in your working directory. Pay attention to the format of the data and do not make any change to the data file.
Write a Python function find_rookie(a, b) here in this cell that takes two non-negative real numbers a and b as input. The function returns a list of all players whose PPG was at least a points per game and MPG is at least b minutes per game. Please use a list for each qualified player, including FN, LN, isAllStar, DRAFT_YR, MPG, and PPG.
Therefore, eventually the function will return a list of list similar to the below:
[[FN1, LN1, isAllStar1, DRAFT_YR1, MPG1, PPG1], [FN2, LN3, isAllStar2, DRAFT_YR2, MPG2, PPG2]]
Here's the part of data from the "NBA.csv" file:
Please help to complete the code below
def find_rookie(a, b):
# start your code below
Thanks!
LN Workman Baechtold Groat Polson Lochmuell Lovellette Davis Conley Denning Grigsby Priddy Walsh Meineke Rhodes Whitaker Zawoluk McLeod Miller Watson Holstein McNulty Bunt Surhoff FN isAllStar DRAFT YRMPG PPG 1 Mark 1952 1952 1952 1952 1952 1952 1952 1952 1952 1952 1952 1952 1952 1952 1952 1952 1952 1952 1952 1952 1952 1952 1952 15.8 29.6 25.5 16.5 12.9 17.4 23.1 11.8 10.3 11.9 3.9 3.7 2 Jim 3 Dick 4 Ralph 5 Bob 6 Clyde 7 Walt 8 Gene 9 Blaine 10 Chuck 0 0 5.9 0 6.4 2.3 11 Bob 0 0 0 0 0 7.2 33.1 17.9 12 Jim 10.7 5.2 0.7 13 Monk 14 Gene 1 5 Skippy 16 Zeke 17 George 18 Eddie 19 Bobby 15.2 8.5 28.8 11.1 15 10.5 20 Jim 0 21 Carl 22 Dick 23 Dick 0 10.4 1.7Explanation / Answer
Hello,
Please find attached code.
=====
import csv
import sys
def find_rookie(a, b):
rain = open("NBA.csv","r")
for line in rain:
try:
ppg = float(line.split(",")[6])
mpg=float(line.split(",")[5])
#if the record satisfy the condition.
if(ppg>=a and mpg>=b):
print(line)
except:
pass
return;
find_rookie(10,20);
======
Sample NBA.csv
1,Mark,Workman,0,1952,15.8,5.1
2,Jim,Baechtold,0,1952,29.6,10.3
3,Dick,Groat,0,1952,25.5,11.9
4,Ralph,Polson,0,1952,16.5,3.9
======
I have just kept 4 as i dont have actual dataset.
====O/P===
============= RESTART: C:/Users/dipal.prajapati/OneDrive/NBA.py =============
2,Jim,Baechtold,0,1952,29.6,10.3
3,Dick,Groat,0,1952,25.5,11.9
Let me know in case of any issues.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.