About this project
There's been much discussion in New York about the city's fluctuating amount of petty crime under Mayor Michael Bloomberg. Using publicly available data from the City of New York's website, I wanted to check and see if there really was a change in petty crime over the course of his three terms as Mayor of New York City. For the purposes of this project, I chose to consider only the rate of misdemeanors in New York City as representative of petty crime.
Importing packages and data
I began by importing a variety of Python packages that would allow me to properly plot and analyze the data found on the City's website. I then imported the data found on the City of New York's data website: https://data.cityofnewyork.us/Public-Safety/Historical-New-York-City-Crime-Data/hqhv-9zeg.
That dataset includes a variety of crime data on not only misdemeanors but also on felonies and violation offenses. For this project, I'll only be examining the file called Misdemeanor Offenses 2000-2011.xls
In [1]:
# import packages
import pandas as pd
import matplotlib.pyplot as plt
import sys
from itertools import cycle, islice
import math
import numpy as np
%matplotlib inline
After importing the required packages, I then imported the data I previously downloaded. For the below code, replace the pathway to the excel spreadsheet with its location on your computer. For the sake of convinience, I created a CSV file from the data so that it would be easier to work with directly.
In [55]:
path = '/Users/zak/Dropbox/*Classes Fall 2016/Data Bootcamp/Misdemeanor Data.csv'
data = pd.read_csv(path)
In [56]:
data.columns
Out[56]:
This gives us a sense for the data we have to work with: at both the individual offense and total offenses levels, we have data on the number of offenses from 2000-2011. Because this doesn't fully cover Mayor Bloomberg's third term in office (which began in 2010 and ended in 2013), we'll only be examining his first two terms in office: 2002 through 2009.
Plotting the total number of offenses during Mayor Bloomberg's two terms
To begin with, I'll plot all of the petty crimes committed in New York over the full period of the dataset. The following labels apply to the below numbers on the graph:
0 MISDEMEANOR POSSESSION OF STOLEN PROPERTY 1 MISDEMEANOR SEX CRIMES (4) 2 MISDEMEANOR DANGEROUS DRUGS (1) 3 MISDEMEANOR DANGEROUS WEAPONS (5) 4 PETIT LARCENY 5 ASSAULT 3 & RELATED OFFENSES 6 INTOXICATED & IMPAIRED DRIVING 7 VEHICLE AND TRAFFIC LAWS 8 MISD. CRIMINAL MISCHIEF & RELATED OFFENSES 9 CRIMINAL TRESPASS 10 UNAUTHORIZED USE OF A VEHICLE 11 OFFENSES AGAINST THE PERSON (7) 12 OFFENSES AGAINST PUBLIC ADMINISTRATION (2) 13 ADMINISTRATIVE CODE (6) 14 FRAUDS (3) 15 AGGRAVATED HARASSMENT 2 16 OTHER MISDEMEANORS (8) 17 TOTAL MISDEMEANOR OFFENSES
Then, I'll plot the total number of crimes over the years 2002-2009. That will give us a baseline idea of the total amount of crime in the city of New York over those years.
In [58]:
data.plot(kind ='bar')
Out[58]:
In [50]:
path = '/Users/zak/Dropbox/*Classes Fall 2016/Data Bootcamp/Misdemeanor Data.csv'
newdata = pd.read_csv(path, skiprows = 0-17, usecols = [3,4,5,6,7,8,9,10])
newd1 = newdata.transpose()
newd1.plot(kind='bar')
Out[50]:
This shows just the total amount of of crime committed (here shown) as label number 17) over just the span of Michael Bloomberg's first two terms as Mayor of New York.
In [ ]: