Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 4 out of 40 pages
Exam (elaborations)

CSE 6040 Midterm 2 Questions and 100% Correct Answers 2026/27 Latest - Georgia Institute Of Technology.

Document preview thumbnail
Preview 4 out of 40 pages

CSE 6040 Midterm 2 Questions and 100% Correct Answers 2026/27 Latest - Georgia Institute Of Technology.

Content preview

CSE 6040 Midterm 2 Questions and 100% Correct Answers 2026/27
Latest - Georgia Institute Of Technology.

Version 1.0.0

All of the header information is important. Please read it..

Topics number of exercises: This problem builds on your knowledge of Working with relational data
(SQL/Pandas), Working with Numpy Arrays. It has 7 exercises numbered 0 to 6. There are 13 available
points. However to earn 100% the threshold is 11 points. (Therefore once you hit 11 points you can stop. There
is no extra credit for exceeding this threshold.)

Exercise ordering: Each exercise builds logically on previous exercises but you may solve them in any order.
That is if you can't solve an exercise you can still move on and try the next one. Use this to your advantage as
the exercises are not necessarily ordered in terms of difficulty. Higher point values generally indicate more
difficult exercises.

Demo cells: Code cells starting with the comment ### define demo inputs load results from prior exercises
applied to the entire data set and use those to build demo inputs. These must be run for subsequent demos to
work properly but they do not affect the test cells. The data loaded in these cells may be rather large (at least in
terms of human readability). You are free to print or otherwise use Python to explore them but we may not print
them in the starter code.

Debugging you code: Right before each exercise test cell there is a block of text explaining the variables
available to you for debugging. You may use these to test your code and can print/display them as needed
(careful when printing large objects you may want to print the head or chunks of rows at a time).

Exercise point breakdown:

Exercise 0 - : 2 point(s)
Exercise 1 - : 1 point(s)
Exercise 2 - : 2 point(s)
Exercise 3 - : 2 point(s)
Exercise 4 - : 2 point(s)
Exercise 5 - : 1 point(s)
Exercise 6 - : 3 point(s)

Final reminders:

Submit after every exercise
Review the generated grade report after you submit to see what errors were returned
Stay calm, skip problems as needed and take short breaks at your leisure




CSE 6040 Midterm 2

, New York Collisions (https://cdn-
uploads.piazza.com/paste/h60voulh3533n3/524396350096ff4fbefa248694bb5658fd3
York-Collisions)
The City of New York collects detailed data on traffic collisions where police are involved. For each collision
information including the date, time, geographic coordinates, vehicle details, and demographics of the people
involved. They make this data and much, much more publicly available on https://opendata.cityofnewyork.us/
(https://opendata.cityofnewyork.us/). We have gone ahead and packaged this data into a SQLite object. The next
code cell opens a connection to it.

In this notebook we're going to explore the structure of the tables in the connection, summarize them, and then
preprocess and analyze geographic data.



In [1]: import re
import pandas as pd
import numpy as np
import sqlite3

conn = sqlite3.connect('file:resource/asnlib/publicdata/traffic.db?mode=ro', u
ri=True)




Structure of tables


There are 3 tables in our connection: CRASHES, VEHICLES, and PERSON. We don't know of the relationships
between the tables or even what columns they contain. The code we will write in the next two exercises will help
find these answers.




Exercise 0: (2 points)


get_table_cols

Your task: define get_table_cols as follows:




CSE 6040 Midterm 2

, Given a SQLite database connection and a table name, determine the column names for that table. Return your
result as a Python list sorted in alphabetical order.

Your function 'get_table_cols' should first verify that the table_name parameter only contains letters, numbers, or
underscores. If that is not the case a ValueError must be raised.

Hint: Your solution will likely require a dynamically generated query, as SQLite does not allow parameters in a
FROM clause.
Hint: If you choose to use a SELECT statement, be mindful of how many rows it returns... It's probably not a
good use of resources to use all of them.




CSE 6040 Midterm 2

, In [23]: ### Solution - Exercise 0

def get_table_cols(table_name, conn):
# GOAL: Determine if table_name contains only alphanumeric characters and
underscores. If not, raise ValueError.
# If so, return sorted list of column names in the table.

# INPUT:
# 'table_name' is a string
# 'conn' is a DB connection

# STRATEGY:
# 1. Check if each character in table_name is alphanumeric or an underscor
e. If not, raise Value Error.
# 2. Find columns in table_name. Sort and return.

# SOLUTION (VERSION 1):
for character in table_name:
if not (character.isalnum() or character == '_'):
raise ValueError

query = f'select * from {table_name} limit 1'
entire_table = pd.read_sql(query, conn)
column_names = entire_table.columns
return sorted(column_names)

#


# SOLUTION (VERSION 2):
for character in table_name:
# If you don't remember regex, .isalnum(), .isalpha(), .isnumeric()..
You can always do something like this!
if character not in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW
XYZ0123456789_':
raise ValueError

# Google Search: 'sqlite get column names from table'
# Google Result: https://stackoverflow.com/questions/947215/how-to-get-a-l
ist-of-column-names-on-sqlite3-database
alternative_query = f'PRAGMA table_info({table_name})'
column_info = pd.read_sql(alternative_query, conn)
column_name_list = sorted(column_info['name'])
return column_name_list


### Demo function call
print(get_table_cols(table_name='vehicles', conn=conn))

['COLLISION_ID', 'CONTRIBUTING_FACTOR_1', 'CONTRIBUTING_FACTOR_2', 'CRASH_DAT
E', 'CRASH_TIME', 'DRIVER_LICENSE_JURISDICTION', 'DRIVER_LICENSE_STATUS', 'DR
IVER_SEX', 'POINT_OF_IMPACT', 'PRE_CRASH', 'PUBLIC_PROPERTY_DAMAGE', 'PUBLIC_
PROPERTY_DAMAGE_TYPE', 'STATE_REGISTRATION', 'TRAVEL_DIRECTION', 'UNIQUE_ID',
'VEHICLE_DAMAGE', 'VEHICLE_DAMAGE_1', 'VEHICLE_DAMAGE_2', 'VEHICLE_DAMAGE_3',
'VEHICLE_ID', 'VEHICLE_MAKE', 'VEHICLE_MODEL', 'VEHICLE_OCCUPANTS', 'VEHICLE_
TYPE', 'VEHICLE_YEAR']

CSE 6040 Midterm 2

Document information

Uploaded on
February 27, 2026
Number of pages
40
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$18.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
DynamicNurse
4.0
(562)
Sold
3874
Followers
2916
Items
1916
Last sold
10 hours ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions