Question: 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.
- 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.
- 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
- 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.
- 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.

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
Get step-by-step solutions from verified subject matter experts
