Mengyao Li
Data Mining the City
3 min readOct 20, 2017

--

The relation between Airbnb location and policing in Harlem, New York

This project intends to show where Airbnb is in relation to the policing in Harlem. Following the emergence and increase of Airbnb worldwide, some people think that Airbnb will induce more crime as more strangers coming into the neighborhood. Harlem, located on the upper Manhattan, has been believed as a neighborhood with high crime rate for a long time. Based on these background, I speculate that Airbnb apartments are located more at the place where there are high crime complaints in Harlem neighborhood. However, the map does not indicated such strong connection. It instead shows a high density of policing and the relatively high crime complaints. Airbnb apartments are actually surrounded with strong policing. There is even no Airbnb near the spots with highest crime complaints number. Besides, Comparing the historic Precinct Crime Statistics from NYPD, most kinds of crime complaints in Harlem even decrease a lot than past years.

The above GIF shows the location of Airbnb in 2017 and the top 100 spots of crime complaints (from 2017.1.1 to 2017.6.31) in Harlem neighborhood. The interactive map can also display the information about specific Airbnb and crime spots.

Data source:

Airbnb listing in 2017: http://insideairbnb.com/get-the-data.html

NYPD Complaint Map (Year to Date): https://data.cityofnewyork.us/Public-Safety/NYPD-Complaint-Map-Year-to-Date-/2fra-mtpn

Borough and Precinct Crime Statistics: http://www1.nyc.gov/site/nypd/stats/crime-statistics/borough-and-precinct-crime-stats.page

Here is the code:

import spatialpixel.mapping.slippymapper as slippymapper
import csv
def setup():
size (1600, 1300, P2D)

pin = loadImage("https://s3.amazonaws.com/spatialpixel/maps/map-pin-10px.png")
global harlem
harlem = slippymapper.SlippyMapper(40.817393, -73.946099, 15, 'carto-dark', width, height)

#this is the Airbnb listing in 2017
with open('airbnb20170902clean.csv') as f:
reader = csv.reader(f)
header = reader.next()

AB=[]
for row in reader:
y={}
latitude_a = float(row[3])
longitude_a = float(row[4])
price = int(row[6])
name = str(row[0])
type = str(row[5])
y['lat'] = latitude_a
y['lng'] = longitude_a
y['price'] = price
y['name'] = name
y['type'] = type
AB.append(y)

for apartment in AB:
harlem.addMarker(apartment['lat'], apartment['lng'], apartmentMarker(apartment))

harlem.addMarker(latitude_a, longitude_a, pin)

harlem.render()

#these are the crime data
with open('Harlem2017_top.csv') as f:
reader = csv.reader(f)
header = reader.next()

nyc=[]
for row in reader:
x={}
latitude_c = float(row[2])
longitude_c = float(row[3])
complaints = int(row[1])
x['lat']=latitude_c
x['lng']=longitude_c
x['complaints']=complaints
nyc.append(x)

for crime in nyc:
harlem.addMarker(crime['lat'], crime['lng'], CrimeMarker(crime))

harlem.render()

def draw():
background(255)
harlem.draw()

#display the text:
fill(150)
textSize(25)
text("Harlem", 800, 650)
text("Hudson River", 200, 650)
#neighborhood
fill(255)
textSize(40)
text("Harlem, New York", 1100, 900)
#information
textSize(25)
text("Apartment type: ", 1000, 1000)
text("Price ($/night): ", 1000, 1050)
text("During 2017.1.1 - 2017.6.31,", 1000, 1150)
text("there are crime complaints.", 1000, 1200)

#display the airbnb logo
global img
img = loadImage("Airbnb-new-logo-2014.png")
img.resize(0,200)
image(img,100,100)
#interactive marker for crime complaints
class CrimeMarker(slippymapper.DataMarker):
def drawMarker(self, x, y, marker):
h = self.data['complaints']
marker.stroke(255)
strokeWeight(1)
marker.fill(150)

if dist(x, y, mouseX, mouseY) < 10:
marker.fill(255,99,71)
fill(255,99,71)
textSize = 25
marker.text(self.data['complaints'], 1125, 1200)

marker.rect(x, y, 6, h * 1.2)
#interactive marker for Airbnb apartments
class apartmentMarker(slippymapper.DataMarker):
def drawMarker(self, x, y, apartmentmarker):

if dist(x, y, mouseX, mouseY) < 10:
fill(255,99,71)
textSize = 25
apartmentmarker.text(self.data['name'], 1000, 950)
apartmentmarker.text(self.data['type'], 1230, 1000)
apartmentmarker.text(self.data['price'], 1230, 1050)

apartmentmarker.text

--

--