Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please solve question 5, I am not sure if the answers I put are correct please answer each part, thank you! Question 2. Create a
Please solve question 5, I am not sure if the answers I put are correct please answer each part, thank you!
Question 2. Create a new table final_scores with three columns in this specific order: Opponent, UCSB Score, Opponent Score. You will have to create the UCSB 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 the arrays and opponent_scores output what you want. 1 import pandas as pd 2 ucsb_scores = games.apply (sum_scores, 1,2) 3 opponent_scores = games. apply (sum_scores,3,4) 4 final_scores = Table () .with_columns ('Opponent', games.column(0), 'UCSB Score', ucsb_scores, 'Opponent Score 5 final_scores ... (11 rows omitted) Question 4. Now we want to see for a particular game whether or not UCSB tied the opponent. Write a function called did_ucsb_tie . It should take one argument: a row object from the final_scores table. It should return either True if UCSB's score was equal to the Opponent's score, and False otherwise. 3] ( \begin{tabular}{l|l} 1 & def did_ucsb_tie(table_row): \\ 2 & ucsb_score = table_row.item('ucSB Score') \\ 3 & opp_score = table_row.item('Opponent Score') \\ 4 & if ucsb_score == opp_score: \\ 5 & return True \\ 6 & else: \\ 7 & return False \end{tabular} 4] : \[ 1 \text { grader. check("q1_4") } \] 4] : q1_4 passed! Question 5. Shoumik wants to see how UCSB did against every opponent during the 2022 season. Using the final_scores table, assign won_games to an array of True and False values that correspond to whether or not UCSB won. Use won_games to calculate the the total number of wins and save the result in ucsb_wins. Likewise, use final_scores to assign tied_games to an array of True if UCSB tied, and False otherwise. Assign the total number of drawn games to ucsb_ties. Finally, assign ucsb_losses to be the total number of losses in the 2022 season. Hint: When you only pass a function name and no column labels through tbl. apply(), the function gets applied to every row in tbl 1 results=final_scores.apply(did_ucsb_win) 2 won_games = 3 ucsb_wins = sum(results) 4 tied_games = 5 ucsb_ties = 6 ucsb_losses = len(results)-ucsb_wins 7 8 \# Don't delete or edit the following line: 9 print(f"In the 2022 Season, UCSB Women's Soccer won_\{ucsb_wins\} games, tied \{ucsb_ties\} games, and lost \{ucsb_lo Cellin[26], line 4 tied_games = SyntaxError: invalid syntaxStep 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