Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you'll be exploring the database of Crime in Denver contained in this zip file. The database contains two files offence_codes.csv: Is a

In this assignment, you'll be exploring the database of Crime in Denver contained in this zip file. The database contains two files

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

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

Begin by downloading a4.py which contains skeleton code that opens and reads the CSV files line-by-line, with an obvious place for you to add your code.

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

Skeleton Code: image text in transcribed Snippet from code cvs file image text in transcribed Snippet from crime cvs file

image text in transcribed

Sample output from teacher

morin@superfiend:~/comp1405$ python -i a4.py >>> code_to_names(2399) ['0: Theft - other', '1: Bicycle theft', '2: Theft of fuel by driving off without paying', '3: Theft of cable services', '4: Theft of construction equipment', '5: Theft of a trailer'] >>> >>> code_to_names(5707) ['0: Criminal trespassing'] >>> >>> codes_from_keywords(['bicycle', 'theft']) [2399] >>> >>> codes_from_keywords(['homicide', 'vehicle']) [] >>> codes_from_keywords(['homicide']) [5450, 7099, 7099, 7099, 902, 903, 904, 907, 908, 910, 911, 912] >>> >>> >>> codes_from_keywords(['homicide', 'police']) [907, 908] >>> >>> >>> codes_from_keywords(['terrorism']) [] >>> codes_from_keywords(['threat']) [5215, 1103] >>> >>> code_to_names(5215) ['0: Bomb threat'] >>> >>> code_to_names(907) ['0: Homicide of a Police Officer w/gun'] >>> >>> >>> code_to_names(908) ['0: Homicide of a Police Officer w/weapon'] >>> >>> crimes_by_code(907) [] >>> >>> crimes_by_code(908) [] >>> >>> bike_thefts = crimes_by_code(2399) >>> len(bike_thefts) 26213 >>> >>> import random >>> random.choice(bike_thefts) ('2016709223', 'theft-other', '11/4/2016 7:10:00 PM', 'baker') >>> >>> random.choice(bike_thefts) ('2018506702', 'theft-other', '7/26/2018 2:16:00 PM', 'speer') >>> >>> random.choice(bike_thefts) ('2016288223', 'theft-other', '5/7/2016 5:00:00 PM', 'university-hills') >>> >>> random.choice(bike_thefts) ('20156002885', 'theft-bicycle', '4/6/2015 6:30:00 PM', 'baker') >>> random.choice(bike_thefts) ('20166005004', 'theft-other', '5/20/2015 7:00:00 PM', 'country-club') >>> random.choice(bike_thefts) ('2017240382', 'theft-other', '4/10/2017 1:00:00 PM', 'lincoln-park') >>> random.choice(bike_thefts) ('20176010956', 'theft-bicycle', '11/17/2017 4:00:00 PM', 'baker') >>> random.choice(bike_thefts) ('2017188807', 'theft-bicycle', '3/22/2017 12:40:00 PM', 'bear-valley') >>> random.choice(bike_thefts) ('201886029', 'theft-other', '1/29/2018 9:00:00 AM', 'west-colfax') >>> random.choice(bike_thefts) ('2015408025', 'theft-bicycle', '7/18/2015 8:30:00 PM', 'congress-park') >>> >>> >>> codes_from_keywords(['homicide']) [5450, 7099, 7099, 7099, 902, 903, 904, 907, 908, 910, 911, 912] >>> >>> code_to_names(5450) ['0: Vehicular homicide'] >>> code_to_names(7099) ['0: Crimes against a person - other', '1: Conspiracy to commit homicide', '2: Solicitation to commit homicide', '3: Reckless endangerment', '4: Disarming a peace officer', '5: Accessory to commit homicide'] >>> >>> >>> a = crimes_by_code(7099) >>> len(a) 177 >>> >>> crimes_by_code_extension(7099, 1) [('2018405726', 'homicide-conspiracy', '6/17/2018 2:32:00 AM', 'bear-valley')] >>> crimes_by_code_extension(7099, 44) [] >>> crimes_by_code_extension(7099, 4) [('2018416946', 'disarming-a-peace-officer', '6/21/2018 6:23:00 PM', 'cbd'), ('201813622', 'disarming-a-peace-officer', '1/6/2018 9:41:00 PM', 'lincoln-park'), ('2018365254', 'disarming-a-peace-officer', '5/31/2018 10:50:00 AM', 'windsor'), ('2018878491', 'disarming-a-peace-officer', '12/31/2018 10:59:00 PM', 'west-colfax'), ('20192419', 'disarming-a-peace-officer', '1/2/2019 8:45:00 AM', 'capitol-hill'), ('2014233261', 'disarming-a-peace-officer', '5/8/2014 12:30:00 AM', 'south-park-hill'), ('2014430822', 'disarming-a-peace-officer', '8/16/2014 8:57:00 PM', 'overland'), ('2014471660', 'disarming-a-peace-officer', '9/6/2014 5:11:00 PM', 'platt-park'), ('2014490308', 'disarming-a-peace-officer', '9/16/2014 11:38:00 AM', 'westwood'), ('2015158108', 'disarming-a-peace-officer', '3/22/2015 7:20:00 PM', 'cbd'), ('201540255', 'disarming-a-peace-officer', '1/20/2015 6:45:00 PM', 'hilltop'), ('2015322253', 'disarming-a-peace-officer', '6/10/2015 3:10:00 PM', 'union-station'), ('2016277324', 'disarming-a-peace-officer', '5/4/2016 12:05:00 PM', 'union-station'), ('2016364649', 'disarming-a-peace-officer', '6/10/2016 6:46:00 PM', 'cbd'), ('201681206', 'disarming-a-peace-officer', '2/7/2016 11:10:00 PM', 'five-points'), ('2017160398', 'disarming-a-peace-officer', '3/10/2017 5:49:00 AM', 'clayton'), ('201875361', 'disarming-a-peace-officer', '1/31/2018 9:45:00 PM', 'hampden-south'), ('201766425', 'disarming-a-peace-officer', '1/30/2017 11:31:00 AM', 'west-colfax'), ('2018471465', 'disarming-a-peace-officer', '7/12/2018 11:50:00 AM', 'auraria'), ('2018293321', 'disarming-a-peace-officer', '5/2/2018 10:22:00 AM', 'platt-park'), ('201647850', 'disarming-a-peace-officer', '1/23/2016 10:52:00 AM', 'south-park-hill'), ('2015663559', 'disarming-a-peace-officer', '11/12/2015 7:40:00 PM', 'chaffee-park'), ('2015350883', 'disarming-a-peace-officer', '6/23/2015 9:40:00 PM', 'cbd'), ('2017342681', 'disarming-a-peace-officer', '5/26/2017 7:01:00 PM', 'five-points'), ('2017320194', 'disarming-a-peace-officer', '5/17/2017 5:35:00 AM', 'cbd'), ('2017797594', 'disarming-a-peace-officer', '11/28/2017 8:25:00 PM', 'five-points'), ('2018553595', 'disarming-a-peace-officer', '8/14/2018 2:48:00 PM', 'cbd')] >>> >>> crimes_by_code_extension(7099, 5) [] >>> 

My Code so far: image text in transcribed

It just returns [ ]

# Question 3 def crimes_by_code (code) return [] # Your code goes here 1 OFFENSE OFFENSE OFFENSE OFFENSE OFFENSE OFFENSE IS CRIME IS TRAFFIC 1 stolen-proPossessio all-other-All Other 2804 2804 2901 2902 2903 o damaged-Damaged public-dis Public Dis o criminal-n Criminal npublic-dis Public Dis o criminal-n Criminal npublic-dis Public Dis o criminal-n Criminal npublic-dis Public Dis 1 criminal-nCriminal npublic-dis Public Dis C) C) C) C) C) C) C) 4 REPORTEC INCID INCIDENT OFFENSEOFFENSEOFFENSE OFFENSEOFFENSE FIRST OCCLAST OCCENT GEOX GEOY GEO LON GEO LAT DISTRICTPRECINCT NEIGHBOF IS CRIME IS_TRAFFIC 22.02E+09 3 2.02 3193983 1707251-104.81 39.77319 3201943 1711852-104.781 39.78565 0 theft-item theft-fron######################## 2932 sos 3152762 1667011-104.957 39.66349 5521montbellc1 522 gateway- 2E+0 2.02E+16 42.02E+10 2.02+162305 5 2.02E 08 2.02+142399 14 wellshire 312 belcaro 311 cherry-cre 622 city-park- O theft-sholarceny 2.02E+09 2.02+15 2303 2.02E+08 2.02E 14 5499 1686545 -104.955 39.71711 # Question 3 def crimes_by_code (code): crimelist [ with open( crime.csv) as csv file: reader csv.reader(csv_file, next(reader) for row in reader: delimiter-.,.) if int (row 21) -- int(code): crimeTuple-(row[e], row[4], row[6], row[16]) crimelist.appent (crimeTuple) return crimelist

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_2

Step: 3

blur-text-image_3

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

What is the role of reward and punishment in learning?

Answered: 1 week ago

Question

. Transcribed image text

Answered: 1 week ago

Question

Understand the post-crisis debate on HRM and pedagogy

Answered: 1 week ago