Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

offence_codes.csv: Is a CSV file that contains offence codes and information about each code crime.csv: Is a CSV file containing information about 455872 crimes reported

offence_codes.csv: Is a CSV file that contains offence codes and information about each code

crime.csv: Is a CSV file containing information about 455872 crimes reported in Denver, mostly occurring in 2018.

  1. Write a function code_to_names(code) that takes an int crime code and returns a list of strings where each string contains the code extension and the full name of the crime.
  2. Write a function code_from_keywords(keywords) that an a list of strings and returns a list of all the crime codes that include all the keywords in their description
  3. Write a function crimes_by_code(code) that returns a list of all the crimes with the given code that have occurred. Each element of the return list is a tuple having he crime id, the abbreviated crime name, the date and time, and neighbourhood id of the crime. See the sample output for an example.
  4. Write a function crimes_by_code_extension(code, extension) that returns a list of all the crimes with the given code and extension that have occurred.

image text in transcribed

Here is the first few rows in text of the crime.csv file for testing:

INCIDENT_ID OFFENSE_ID OFFENSE_CODE OFFENSE_CODE_EXTENSION OFFENSE_TYPE_ID OFFENSE_CATEGORY_ID FIRST_OCCURRENCE_DATE LAST_OCCURRENCE_DATE REPORTED_DATE INCIDENT_ADDRESS GEO_X GEO_Y GEO_LON GEO_LAT DISTRICT_ID PRECINCT_ID NEIGHBORHOOD_ID IS_CRIME IS_TRAFFIC
2.02E+09 2.02E+15 5213 0 weapon-unlawful-discharge-of all-other-crimes 6/15/2016 11:31:00 PM 6/15/2016 11:31:00 PM 3193983 1707251 -104.81 39.77319 5 521 montbello 1 0
2.02E+10 2.02E+16 2399 0 theft-other larceny 10/11/2017 12:30:00 PM 10/11/2017 4:55:00 PM 1/29/2018 5:53:00 PM 3201943 1711852 -104.781 39.78565 5 522 gateway-green-valley-ranch 1 0
2.02E+10 2.02E+16 2305 0 theft-items-from-vehicle theft-from-motor-vehicle 3/4/2016 8:00:00 PM 4/25/2016 8:00:00 AM 4/26/2016 9:02:00 PM 2932 S JOSEPHINE ST 3152762 1667011 -104.957 39.66349 3 314 wellshire 1 0

Here is the first few rows in text of the offense_codes.csv file for testing:

OFFENSE_CODE OFFENSE_CODE_EXTENSION OFFENSE_TYPE_ID OFFENSE_TYPE_NAME OFFENSE_CATEGORY_ID OFFENSE_CATEGORY_NAME IS_CRIME IS_TRAFFIC
2804 1 stolen-property-possession Possession of stolen property all-other-crimes All Other Crimes 1 0
2804 2 fraud-possess-financial-device Possession of a financial device all-other-crimes All Other Crimes 1 0
2901 0 damaged-prop-bus Damaged business property public-disorder Public Disorder 1 0
1 import csv # Question 1 6def code_to_names (code): with open offense_codes.csv') as csv_file: reader csv.reader (csv file, delimiter-',') next(reader) # skip the first row for row in reader: 9 10 12 13 14 pass # Your code goes here return names 16 # Question 2 17 18 def codes_from_keywords (keywords): 19 20 with open( offense_codes.csv) as csvfile: 21 codelist = [] reader csv.reader(csv_file, delimiter-,) next(reader) # skip the first row for row in reader: 23 24 25 26 pass return codelist 28 # Question 3 30 def crimes_by_code(code): 31 return [] # Your code goes here 32 34 # Question 4 def crimes_by_code_extension(code, extension): 36 37 38 39 40 41 42 43 crimes = [] with open( crime.csv') as csv file: reader csv.reader(csv_file, delimiter-" next(reader) # skip the first row for row in reader: pass # Your code goes here return crimes

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

=+3. Which factors do influence the procurement management?

Answered: 1 week ago

Question

=+1. Describe the product range in the press sector!

Answered: 1 week ago