- There is an Ed discussion thread (https://edstem.org/us/courses/18760/discussion/1464598) that will specify completion and submission instructions.
Due Date, Completing the Exam and Rules
- The fifinal exam is due at 11:59 PM on Monday, 08-May-2022. You are not allowed to use late days.
- You may use on-line information and sources to answer questions. But,
a.You cannot simply cut and paste answers or code. Your answer must demonstrate that you understood the material and are capable of producing an answer from your understanding.
b.You must cite any sources of information that you used. This can simply be a comment in a text/markdown cell in your answer. For example, (Note: I used https://www.w3schools.com/sql/sql_check.asp to help me with the syntax for adding a check constraint).The following cell(s) load information about CU courses.
c.You do NOT need to cite lecture notes, recordings, slides, … You do not need to cite information from the recommended textbook or textbook slides.
- You MUST NOT collaborate with ANYONE, including other students. You MAY speak with the professor or a TA to discuss the exam.
- If you have questions, post them as PRIVATE question on Ed discussion and use the Category Exams->Final.
- There is a pinned Ed discussion thread Midterm Clarififications (https://edstem.org/us/courses/18760/discussion/1464595) that the professor and TA will use to communicate updates and clarififications. Students are responsible for checking this post.
- Individual questions provide explanations for how to complete the question.
Environment Setup and Test
- This section tests your environment.
- You will need to change the URLs and password in some of the cells below to match your confifiguration.
- You may need to load data and copy databases. The relevant questions provide information.
- You must read the comments in the setup cells. You will need objects and functions in the cells for some questions.
In :%load_ext sql
In :# Connect to MySQL. Replace dbuser:dbuserdbuser with your MySQL user ID and password. %sql mysql+pymysql://dbuser:dbuserdbuser@localhost
In :from sqlalchemy import create_engine
In :# Create an SQL Alchemy engine for using MySQL. Replace dbuser:dbuserdbuser with your user ID and password. sql_engine = create_engine(“mysql+pymysql://dbuser:dbuserdbuser@localhost”)
In :import pandas as pd
In :import pymysql
In :def get_mysql_connection(user_id, password, autocommit=True):
Creates and return a connection to the local MySQL database.
:param user_id: The user ID for the connection.
:param password: Corresponding password.
:param autocommit: Should this connection use autocommit for executed statements. See the following
sql_conn = pymysql.connect(
Closes a connection.
:param sql_connection: The connection to close.
In : You must set these parameters to the values for you final submission and databases.
# Replace dff9 with your UNI
mysql_url = “mysql+pymysql://dbuser:dbuserdbuser@localhost”
final_schema = “dff9_s22_final”
course_info_table = “course_info”
course_info_file = “./course_info.json”
In :read_and_save_json_file(file_name, schema_name, table_name):
df = pd.read_json(file_name)
eng = create_engine(mysql_url)
df.to_sql(table_name, schema=schema_name, con=eng, index=False, if_exists=“replace”)
In :%sql create database if not exists dff9_s22_final
read_and_save_json_file(course_info_file, final_schema, course_info_table)
%sql use $final_schema
callnumber, schoolcode, coursetitle, coursesubtitle,
where instructor1name like “%Ferguson%Donald%”