Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Please use Part 1 to solve Part 2 In [1]: # Don't change this cell; just run it. import numpy as np from datascience import

Please use Part 1 to solve Part 2

image text in transcribedimage text in transcribed

In [1]: # Don't change this cell; just run it. import numpy as np from datascience import * # These lines do some fancy plotting magic. import matplotlib %matplotlib inline import matplotlib.pyplot as plt plt.style.use('fivethirtyeight') import warnings warnings.simplefilter('ignore', FutureWarning) from client.api.notebook import Notebook ok = Notebook ('hw05.ok') = ok.auth(inline=True) 1. 2019 Cal Football Season Shoumik is trying to analyze how well the Cal football team performed in the 2019 season. A football game is divided into four periods, called quarters. The number of points Cal scored in each quarter, and the number of points their opponent scored in each quarter are stored in a table called cal_fb.csv. In [2]: # Just run this cell # Read in the cal_fb csv file games = Table().read_table("cal_fb.csv") games.show() Let's start by finding the total points each team scored in a game. Question 1. Write a function called sum_scores . It should take four arguments, where each argument is the team's score for that quarter. It should return the team's total score for that game. In [3]: def sum_scores(...): "Returns the total score calculated by adding up the score of each qua sum_scores (14, 7, 3, 0) #DO NOT CHANGE THIS LINE Question 2. Create a new table final_scores with three columns in this specific order: Opponent , Cal Score , Opponent Score . You will have to create the Cal Score and Opponent Score columns. Use the function sum_scores you just defined in the previous question for this problem. Hint: If you want to apply a function that takes in multiple arguments, you can pass multiple column names as arguments in tbl.apply(). The column values will be passed into the corresponding arguments of the function. Take a look at the python reference for syntax. Tip: If you're running into issues creating final_scores, check that cal_scores and opponent_scores output what you want. In [6]: cal_scores = ... opponent_scores = ... final_scores = ... final_scores In [ ]: ok.grade("q1_2"); We can get specific row objects from a table. You can use tbl.row(n) to get the nth row of a table.row.item("column_name") will allow you to select the element that corresponds to column_name in a particular row. Here's an example: In [10]: # Just run this cell # We got the Axe! games.row (10) In [11]: # Just run this cell games.row(10).item("Cal 4Q") In [1]: # Don't change this cell; just run it. import numpy as np from datascience import * # These lines do some fancy plotting magic. import matplotlib %matplotlib inline import matplotlib.pyplot as plt plt.style.use('fivethirtyeight') import warnings warnings.simplefilter('ignore', FutureWarning) from client.api.notebook import Notebook ok = Notebook ('hw05.ok') = ok.auth(inline=True) 1. 2019 Cal Football Season Shoumik is trying to analyze how well the Cal football team performed in the 2019 season. A football game is divided into four periods, called quarters. The number of points Cal scored in each quarter, and the number of points their opponent scored in each quarter are stored in a table called cal_fb.csv. In [2]: # Just run this cell # Read in the cal_fb csv file games = Table().read_table("cal_fb.csv") games.show() Let's start by finding the total points each team scored in a game. Question 1. Write a function called sum_scores . It should take four arguments, where each argument is the team's score for that quarter. It should return the team's total score for that game. In [3]: def sum_scores(...): "Returns the total score calculated by adding up the score of each qua sum_scores (14, 7, 3, 0) #DO NOT CHANGE THIS LINE Question 2. Create a new table final_scores with three columns in this specific order: Opponent , Cal Score , Opponent Score . You will have to create the Cal Score and Opponent Score columns. Use the function sum_scores you just defined in the previous question for this problem. Hint: If you want to apply a function that takes in multiple arguments, you can pass multiple column names as arguments in tbl.apply(). The column values will be passed into the corresponding arguments of the function. Take a look at the python reference for syntax. Tip: If you're running into issues creating final_scores, check that cal_scores and opponent_scores output what you want. In [6]: cal_scores = ... opponent_scores = ... final_scores = ... final_scores In [ ]: ok.grade("q1_2"); We can get specific row objects from a table. You can use tbl.row(n) to get the nth row of a table.row.item("column_name") will allow you to select the element that corresponds to column_name in a particular row. Here's an example: In [10]: # Just run this cell # We got the Axe! games.row (10) In [11]: # Just run this cell games.row(10).item("Cal 4Q")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions