f22-final
.pdf
keyboard_arrow_up
School
University of Wisconsin, Madison *
*We aren’t endorsed by this school
Course
220
Subject
Computer Science
Date
Feb 20, 2024
Type
Pages
18
Uploaded by DrMinkMaster867
CS 220 - Fall 2022
Instructors: Meenakshi Syamkumar, Mike Doescher, and Gurmail Singh
Final — 10%
(Last) Surname:
(First) Given name:
NetID (email):
@wisc.edu
Fill in these fields (left to right) on the scantron form (use #2 pencil):
1. LAST NAME (surname) and FIRST NAME (given name), fill in bubbles
2. IDENTIFICATION NUMBER is your Campus ID number, fill in bubbles
3. Under
ABC
of SPECIAL CODES, write your lecture number, fill in bubbles:
001 - MWF 11:00am (Meena)
002 - MWF 1:20pm (Meena)
003 - MWF 8:50am (Gurmail)
004 - MWF 9:55am (Mike)
005 - MWF 3:30pm (Mike)
006 - MWF 1:20pm (Gurmail)
4. Under
F
of SPECIAL CODES, write
A
and fill in bubble
6
If you miss step 4 above (or do it wrong), the system may not
grade you against the correct answer key, and your grade will be
no better than if you were to randomly guess on each question. So
don’t forget!
You may only reference your note sheet. You may not use books, your neighbors, calculators,
or other electronic devices during this exam. Please place your student ID face up on your
desk. Turn off and put away portable electronics (including smart watches) now.
Use a #2 pencil to mark all answers. When you’re done, please hand in the exam and note
sheet and your filled-in scantron form. The note sheet will not be returned.
Page 1 of 18
Smartphones (Pandas)
Consider the following code:
import pandas as pd
smartphones_dict = {
"Model": ["iPhone 13", "iPhone 13 Pro Max", "iPhone 12", \
"Galaxy S22 Ultra", "Galaxy A13"],
"Manufacturer": ["Apple", "Apple", "Apple", "Samsung", "Samsung"],
"Release Year": [2021, 2021, 2020, 2022, 2022],
"Cost ($)": [799, 1099, 599, 955, 149],
"Market Share (in %)": [5.5, 3.4, 1.6, 1.4, 1.4]
}
smartphones = pd.DataFrame(smartphones_dict)
1. What data type does
smartphones["Manufacturer"].value
counts()
return?
A. int
B. dict
C. str
D. Series
E. DataFrame
2. What will the inner data structures in
smartphones
dict
represent in the
smartphones
DataFrame?
A. rows
B. columns
C. DataFrames
D. lists
3. How can we get the name of the most expensive
Model
?
A.
smartphones["Cost (
$
)"].max()["Model"]
B.
smartphones["Model"]["Cost (
$
)"].max()
C.
smartphones[smartphones["Cost (
$
)"] == smartphones["Cost
(
$
)"].max()]["Model"]
D.
smartphones["Cost (
$
)"] == smartphones["Cost (
$
)"].max()["Model"]
4. How can we get the name of the least expensive
Manufacturer
for each
Release Year
?
A.
smartphones["Cost (
$
)"].value
counts().min()[["Manufacturer",
"Release Year"]]
B.
smartphones[["Manufacturer", "Release Year", "Cost (
$
)"]]["Cost
(
$
)"].value
counts().min()
C.
smartphones[smartphones["Cost (
$
)"] == smartphones["Cost
(
$
)"].min()][["Manufacturer", "Release Year"]]
D.
smartphones["Release Year"].groupby("Release
Year")[["Manufacturer", "Cost (
$
)"]].min()
E.
smartphones[["Manufacturer", "Release Year", "Cost
(
$
)"]].groupby("Release Year").min()
Page 2 of 18
5. Suppose the shop selling these smartphones wants to provide a Christmas season discount
of 10% to all of the phones. Which of the following will allow us to add a new column called
Sale Cost (
$
)
(cost after the 10% discount) to the
smartphones
DataFrame?
A.
smartphones["Sale Cost (
$
)"] = smartphones["Cost (
$
)"] * 10 / 100
B.
smartphones["Sale Cost (
$
)"] = smartphones["Cost (
$
)"].apply(lambda
c:
c - (c * 10 / 100))
C.
smartphones["Sale Cost (
$
)"] = smartphones["Cost (
$
)"].apply(c * 10
/ 100)
D.
smartphones["Cost (
$
)"] - (smartphones["Cost (
$
)"] * 10 / 100)
6. Which of the following expressions will
NOT
help us extract
iPhone 13
’s
Market Share
(in %)
? Note: ignore hard coding assumptions to answer this question.
A.
smartphones.iloc[0]["Market Share (in %)"]
B.
smartphones.loc[0]["Market Share (in %)"]
C.
smartphones.iloc[0].loc["Market Share (in %)"]
D.
smartphones.loc[0].loc[4]
E.
smartphones.loc[0].loc["Market Share (in %)"]
7. Find the average price of phones sold by
Apple
.
A.
mean(smartphones[smartphones["Manufacturer"] == "Apple"]["Cost
(
$
)"])
B.
smartphones[smartphones["Manufacturer"] == "Apple"]["Cost
(
$
)"].mean()
C.
(smartphones["Manufacturer"] == "Apple")["Cost (
$
)"].mean()
D.
smartphones[smartphones["Manufacturer"] == "Apple"]["Cost
(
$
)"].sum() / len(smartphones)
8. How can we sort the
smartphones
DataFrame based on decreasing order of
"Release Year"
?
A.
smartphones.sort
values(by="Release Year", ascending=False)
B.
smartphones.sort
values(by="Release Year", descending=True)
C.
smartphones.sort
values(by="Release Year", reverse=True)
D.
smartphones.sort
index(by="Release Year", reverse=True)
Page 3 of 18
FIFA (Database)
Consider the following code, and the corresponding output:
import sqlite3
import pandas as pd
conn = sqlite3.connect("fifa.db")
fifa_scores = pd.read_sql("SELECT * from fifa_top_scorers", conn)
fifa_scores
player
name
country
goals
scored
year
0
Alex Morgan
USA
6
2019
1
Harry Kane
England
6
2018
2
James Rodriguez
Colombia
6
2014
3
Thomas Muller
Germany
5
2010
4
David Villa
Spain
5
2010
5
Miroslav Klose
Germany
5
2006
9. Which SQL clause enables us to narrow down columns of interest?
A.
SELECT
B.
FROM
C.
WHERE
D.
GROUP BY
E.
LIMIT
10. How many rows will the following SQL query return?
SELECT COUNT(player_name) FROM fifa_top_scorers GROUP BY goals_scored LIMIT 4
A. 0
B. 1
C. 2
D. 3
E. 4
11. Sort by descending order of
year
, the rows of players whose
goals
scored
is more than 5.
A.
SELECT FROM fifa
top
scorers WHERE goals
scored > 5 ORDER BY year
DESC
B.
SELECT * FROM fifa
top
scorers WHERE goals
scored > 5 ORDER BY DESC
year
C.
SELECT * FROM fifa
top
scorers WHERE goals
scored > 5 ORDER BY year
DSC
D.
SELECT * FROM fifa
top
scorers WHERE goals
scored > 5 ORDER BY year
DESC
12. Which
player
name
will be
excluded
when we execute the below SQL query?
SELECT player_name FROM fifa_top_scorers WHERE year >= 2010 AND year < 2020
A. Alex Morgan
B. Thomas Muller
C. David Villa
D. Miroslav Klose
Page 4 of 18
13. Which SQL query produces a similar output to the following
pandas
expression?
fifa_scores[fifa_scores["country"] == "Germany"]["goals_scored"].mean()
A.
SELECT goals
scored FROM fifa
top
scorers WHERE country = "Germany"
ORDER BY goals
scored DESC
B.
SELECT AVG(goals
scored) FROM fifa
top
scorers WHERE country =
"Germany"
C.
SELECT SUM(goals
scored)/MAX(goals
scored) FROM fifa
top
scorers
WHERE country = "Germany"
D.
SELECT AVG(goals
scored) FROM fifa
top
scorers GROUP BY country
14. Which
pandas
expression will produce the closest results to the following SQL query?
SELECT country, MAX(goals_scored) FROM fifa_top_scorers GROUP BY country
A.
fifa
scores["country"].value
counts().max()
B.
fifa
scores["goals
scored"].value
counts().max()
C.
fifa
scores[fifa
scores["goals
scored"] ==
fifa
scores["goals
scored"].max()]
D.
fifa
scores[["country", "goals
scored"]].groupby("country").max()
15. Which SQL query answers the following question:
Which
year
(s) had more than 6
goals
scored
in total?
A.
SELECT year, SUM(goals
scored) AS total
goals FROM fifa
top
scorers
WHERE HAVING total
goals > 6 GROUP BY year
B.
SELECT year, SUM(goals
scored) AS total
goals FROM fifa
top
scorers
GROUP BY year HAVING total
goals > 6
C.
SELECT year, SUM(goals
scored) AS total
goals FROM fifa
top
scorers
GROUP BY year ORDER BY total
goals DESC
D.
SELECT year, SUM(goals
scored) AS total
goals FROM fifa
top
scorers
GROUP BY total
goals LIMIT 1
Page 5 of 18
Grades (Plotting)
The top 5 rows within
majors
df
DataFrame are displayed below. Assume that
majors
df
DataFrame contains many rows.
GPA
Time studied (hours)
Major
0
3.64
16.45
Data Science
1
3.20
13.95
Biology
2
2.95
5.97
Biology
3
3.16
9.22
Engineering
4
2.50
4.42
Economics
...
...
...
...
16. Which of the following options will generate a scatter plot having “Time studied (hours)”
on the x-axis and and “GPA” on the y-axis for all students pursuing the “Data Science”
major?
A.
(majors
df["Major"] == "Data Science").set
index("GPA")["Time
studied (hours)"].plot.scatter()
B.
majors
df[majors
df["Major"] == "Data Science"].plot.scatter(x="Time
studied (hours)", y="GPA")
C.
majors
df[majors
df["Major"] == "Data Science"].plot.scatter(x="GPA",
y="Time studied (hours)")
D.
(majors
df["Major"] == "Data Science").set
index("Time studied
(hours)")["GPA"].plot.scatter()
17. Refer to the provided sample rows in
majors
df
for answering this question. Which of the
following options should replace Line 1 in the code snippet below to create the
best line
plot
between “Time studied (hours)” (x-axis) and “GPA” (y-axis)?
ax = majors_df.plot.line(x = "Time studied (hours)", y = "GPA")
# Line 1
ax.set_xlabel("Time studied (hours)")
# Line 2
ax.set_ylabel("GPA")
# Line 3
A.
ax = majors
df.sort
values(by="Time studied (hours)").plot.line(x="Time
studied (hours)", y="GPA")
B.
ax = majors
df.sort
values(by="GPA").plot.line(x="Time studied
(hours)", y="GPA")
C.
ax = majors
df.sort
index().plot.line(x="Time studied (hours)",
y="GPA")
D.
ax = majors
df.set
index("Time studied (hours)").plot.line(y="GPA")
Page 6 of 18
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
A key attribute:
Group of Choice:
A. identifies a column
B. can only be one column
C. uniquely identifies a row
arrow_forward
write access model Only Leena can access her laptop. The website can be accessed only during work time The file is a read-only file. Only course instructors can access students' data.
arrow_forward
Question 56
arrow_forward
EXPERIMENTAL PROCEDURE
Patients visit the hospital and their visit history is maintained by the hospital staff. Different physicians may be available on different dates. They diagnose and treat the patients of all categories. Some of treatments are free while others are to be paid by the patients. Sample data of the case is shown in the following chart.
Patient History Report
PatientID
Name
Address
Visit Date
Physician
Diagnosis
Treatment
P-100809
A
City: X
12-02-2007
20-02-2007
29-02-2007
15-03-2007
Dr. Z
Dr. F
Dr. R
Dr. L
Chest Infection
Cold
Hepatitis-A
Eyes Infection
Free
Free
Paid
Paid
P-200145
N
City: Y
10-01-2007
15-02-2007
25-03-2007
Dr. L
Dr. K
Dr. A
Bone Fracture
Cough
Flu
Paid
Free
Free
Task 1
Draw a dependency diagram and transform the above data to first normal form by eliminating repeating groups such that each row in the relation is atomic. Be sure to create an appropriate name for the…
arrow_forward
Use Mysql code
The database has three tables for tracking horse-riding lessons:
Horse with columns:
ID - primary key
RegisteredName
Breed
Height
BirthDate
Student with columns:
ID - primary key
FirstName
LastName
Street
City
State
Zip
Phone
EmailAddress
LessonSchedule with columns:
HorseID - partial primary key, foreign key references Horse(ID)
StudentID - foreign key references Student(ID)
LessonDateTime - partial primary key
Write a SELECT statement to create a lesson schedule for Feb 1, 2020 with the lesson date/time, student's first and last names, and the horse's registered name. Order the results in ascending order by lesson date/time, then by the horse's registered name. Make sure unassigned lesson times (student ID is NULL) appear in the results.
Hint: Perform a join on the LessonSchedule, Student, and Horse tables, matching the student IDs and horse IDs.
arrow_forward
Computer Science
A study conducted by Netflix’s consumer relations department has revealed that customers are more likely to review horror and thriller movies during certain months of the year. To discourage seasonal variations in these movie ratings, Netflix has called for your help to analyze horror and thriller movie rating counts over the past 15 years. Your query should display each month of the year (name of the month not the number) and the total number of ratings given during that month. A third column titled “Promotion Recommendation” determines whether a promotion should be applied to increase the number of ratings given during that month. If a month has less than 2200 ratings the final column should display ‘10% discount promotion’, if between 2201 and 4500 then display ‘5% discount promotion’, and if more than 4500 ratings then output ‘No Promotion’. Order your results by months. Do not hardcode the current date.
ORALCE CODE PLEASE.
arrow_forward
Question: True or False
1) the data in an excel table can be sorted into both, ascending and descending order.
reqiured:
please answer this question by giving the correct answer by stating whether this statement is true or false
arrow_forward
Alreej College
Computer
Application
Student Name Student_ID
Math
En
Ahmed Omar
Huda
20f20
45
10
35
20f21
50
45
45
Muhmmed
20f22
20f23
20f24
20f25
46
20
50
Amira
50
35
50
Huda Ahemd
20
50
33
Noora Ali
33
45
46
Figure-1
1) Prepare and format your MS-Excel Document as shown above.
2) The total number of student marks for each Module during the semester needs to be calculated.
Explain how you will do it. Your answer should include cell references to indicate the cells where the
calculations will be done, the cells that will be required for the calculations, and the formula to be
used. Use Microsoft Excel to test your explanations.
3) Explain how you will calculate the Average for each students. Your answer should include cell
references to indicate the cells where the calculations will be done, the cells that will be required for
the calculations, and the formula to
be used. Use Microsoft Excel to test your
explanations.
arrow_forward
Course Title: Data Structure and Algorithms
Question
A table stores the data for all the members of an exotic resort. Members are identified by these numbers 1,5,30,70,80,20,15,100,40,25,7,3,8,33,22.
All members are to be invited in a meeting to review the membership policies. What will be the fastest way to call all the members? Write algorithm to justify your answer.
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781305627482
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781285196145
Author:Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos Coronel
Publisher:Cengage Learning
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:9780357392676
Author:FREUND, Steven
Publisher:CENGAGE L
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Related Questions
- A key attribute: Group of Choice: A. identifies a column B. can only be one column C. uniquely identifies a rowarrow_forwardwrite access model Only Leena can access her laptop. The website can be accessed only during work time The file is a read-only file. Only course instructors can access students' data.arrow_forwardQuestion 56arrow_forward
- EXPERIMENTAL PROCEDURE Patients visit the hospital and their visit history is maintained by the hospital staff. Different physicians may be available on different dates. They diagnose and treat the patients of all categories. Some of treatments are free while others are to be paid by the patients. Sample data of the case is shown in the following chart. Patient History Report PatientID Name Address Visit Date Physician Diagnosis Treatment P-100809 A City: X 12-02-2007 20-02-2007 29-02-2007 15-03-2007 Dr. Z Dr. F Dr. R Dr. L Chest Infection Cold Hepatitis-A Eyes Infection Free Free Paid Paid P-200145 N City: Y 10-01-2007 15-02-2007 25-03-2007 Dr. L Dr. K Dr. A Bone Fracture Cough Flu Paid Free Free Task 1 Draw a dependency diagram and transform the above data to first normal form by eliminating repeating groups such that each row in the relation is atomic. Be sure to create an appropriate name for the…arrow_forwardUse Mysql code The database has three tables for tracking horse-riding lessons: Horse with columns: ID - primary key RegisteredName Breed Height BirthDate Student with columns: ID - primary key FirstName LastName Street City State Zip Phone EmailAddress LessonSchedule with columns: HorseID - partial primary key, foreign key references Horse(ID) StudentID - foreign key references Student(ID) LessonDateTime - partial primary key Write a SELECT statement to create a lesson schedule for Feb 1, 2020 with the lesson date/time, student's first and last names, and the horse's registered name. Order the results in ascending order by lesson date/time, then by the horse's registered name. Make sure unassigned lesson times (student ID is NULL) appear in the results. Hint: Perform a join on the LessonSchedule, Student, and Horse tables, matching the student IDs and horse IDs.arrow_forwardComputer Science A study conducted by Netflix’s consumer relations department has revealed that customers are more likely to review horror and thriller movies during certain months of the year. To discourage seasonal variations in these movie ratings, Netflix has called for your help to analyze horror and thriller movie rating counts over the past 15 years. Your query should display each month of the year (name of the month not the number) and the total number of ratings given during that month. A third column titled “Promotion Recommendation” determines whether a promotion should be applied to increase the number of ratings given during that month. If a month has less than 2200 ratings the final column should display ‘10% discount promotion’, if between 2201 and 4500 then display ‘5% discount promotion’, and if more than 4500 ratings then output ‘No Promotion’. Order your results by months. Do not hardcode the current date. ORALCE CODE PLEASE.arrow_forward
- Question: True or False 1) the data in an excel table can be sorted into both, ascending and descending order. reqiured: please answer this question by giving the correct answer by stating whether this statement is true or falsearrow_forwardAlreej College Computer Application Student Name Student_ID Math En Ahmed Omar Huda 20f20 45 10 35 20f21 50 45 45 Muhmmed 20f22 20f23 20f24 20f25 46 20 50 Amira 50 35 50 Huda Ahemd 20 50 33 Noora Ali 33 45 46 Figure-1 1) Prepare and format your MS-Excel Document as shown above. 2) The total number of student marks for each Module during the semester needs to be calculated. Explain how you will do it. Your answer should include cell references to indicate the cells where the calculations will be done, the cells that will be required for the calculations, and the formula to be used. Use Microsoft Excel to test your explanations. 3) Explain how you will calculate the Average for each students. Your answer should include cell references to indicate the cells where the calculations will be done, the cells that will be required for the calculations, and the formula to be used. Use Microsoft Excel to test your explanations.arrow_forwardCourse Title: Data Structure and Algorithms Question A table stores the data for all the members of an exotic resort. Members are identified by these numbers 1,5,30,70,80,20,15,100,40,25,7,3,8,33,22. All members are to be invited in a meeting to review the membership policies. What will be the fastest way to call all the members? Write algorithm to justify your answer.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781305627482Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningNp Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:CengageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781285196145Author:Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos CoronelPublisher:Cengage Learning
- COMPREHENSIVE MICROSOFT OFFICE 365 EXCEComputer ScienceISBN:9780357392676Author:FREUND, StevenPublisher:CENGAGE LProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781305627482
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781285196145
Author:Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos Coronel
Publisher:Cengage Learning
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:9780357392676
Author:FREUND, Steven
Publisher:CENGAGE L
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage