Question
import csv def player_stats(csv_data_file): # Returns a dictionary that maps each player name to a dictionary of statistics' players_dict= {} header = [] with open(csv_data_file)
import csv
def player_stats(csv_data_file): # Returns a dictionary that maps each player name to a dictionary of statistics' players_dict= {} header = [] with open(csv_data_file) as csvfile: csvReader = csv.reader(csvfile, delimiter=',') row_number = 1 for row in csvReader: rowDict = {} if row_number ==1: header = row else: for i in range(1,len(row)): rowDict[header[i]] = row[i] players_dict[row[0]] = rowDict row_number +=1
return players_dict
players1 = player_stats('Quarterbacks.csv')
Using the function above for a csv file, write loops to retrieve data in the following ways, indicated on the comments of the initial Python file. Please see complete testing results of the program below.
For Quarterback data:
# compute average number of touch downs
# find player with maximum number of completions
# find players with more than 5 touch downs
>>>> (Outputs for Quarterback data)
** Average number of touch downs: 3.15
** Player with most completions: Aaron Rodgers with 107.0 completions
** Players with more than 5 touch downs: ['Drew Brees', 'Tom Brady', 'Matthew Stafford', 'Alex Smith', 'Blake Bortles', 'Aaron Rodgers', 'Derek Carr', 'Trevor Siemian']
For NBA data:
# compute average number of PPG
# find player with minimum number of FT%
# find players for team CHI
>>>>>> (Outputs for NBA data)
** Average number of PPG's: 16.31
** Player with minimum FT%: Andre Drummond with 0.386 FT%
** Players on Team CHI: ['Nikola Mirotic', 'Jimmy Butler', 'Robin Lopez']
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started