In [1]:
import pandas as pd

quality = pd.read_csv('311_Service_Requests_from_2015.csv')


/usr/lib/python2.7/site-packages/IPython/core/interactiveshell.py:2717: DtypeWarning: Columns (8,17,40,41,42,43,44,45,46,47,48,49) have mixed types. Specify dtype option on import or set low_memory=False.
  interactivity=interactivity, compiler=compiler, result=result)

In [ ]:
quality.keys()

In [ ]:
#quality

In [ ]:
#print quality.iloc[1]

In [3]:
quality.Borough.unique()


Out[3]:
array(['QUEENS', 'MANHATTAN', 'BRONX', 'BROOKLYN', 'Unspecified',
       'STATEN ISLAND'], dtype=object)

In [4]:
# Seperate in to Boroughs
bourough_names = ["BROOKLYN", "QUEENS", "MANHATTAN", "BRONX", "STATEN ISLAND"]
brooklynQ = quality[quality['Borough'] == "BROOKLYN"] 
queensQ = quality[quality['Borough'] == "QUEENS"] 
manhattanQ = quality[quality['Borough'] == "MANHATTAN"] 
bronxQ = quality[quality['Borough'] == "BRONX"] 
statenIslandQ = quality[quality['Borough'] == "STATEN ISLAND"]

In [5]:
# Reset Indexs
brooklynQ = brooklynQ.reset_index(drop=True)
queensQ = queensQ.reset_index(drop=True)
manhattanQ = manhattanQ.reset_index(drop=True)
bronxQ = bronxQ.reset_index(drop=True)
statenIslandQ = statenIslandQ.reset_index(drop=True)

In [ ]:
#print queensQ['Unique Key'].count()
#print brooklynQ['Unique Key'].count()
#print manhattanQ['Unique Key'].count()
#print bronxQ['Unique Key'].count()
#print statenIslandQ['Unique Key'].count()

In [ ]:
'Noise - Vehicle' 'Noise' 'Noise - Residential' 'Noise - Street/Sidewalk'

In [ ]:
#quality['Agency Name'].unique()

In [26]:
# Types of complaints
top5_agencies = quality['Agency Name'].value_counts()[:5]


Out[26]:
['Department of Housing Preservation and Development',
 'New York City Police Department',
 'Department of Transportation',
 'Department of Environmental Protection',
 'Department of Parks and Recreation']

In [ ]:
# Types of complaints
#print quality['Complaint Type'].value_counts().to_string()

In [7]:
awer = quality[quality['Agency Name'] == 'Department of Housing Preservation and Development']

In [8]:
awer = awer[awer.Latitude >= 0]
awer


Out[8]:
Unique Key Created Date Closed Date Agency Agency Name Complaint Type Descriptor Location Type Incident Zip Incident Address ... Bridge Highway Name Bridge Highway Direction Road Ramp Bridge Highway Segment Garage Lot Name Ferry Direction Ferry Terminal Name Latitude Longitude Location
30 31931071 11/06/2015 06:31:06 AM 11/10/2015 11:19:26 AM HPD Department of Housing Preservation and Develop... UNSANITARY CONDITION PESTS RESIDENTIAL BUILDING 10457 1530 SHERIDAN AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.841497 -73.911136 (40.84149732499304, -73.91113593339)
55 31795240 10/19/2015 07:51:41 AM 10/27/2015 01:12:23 AM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER APARTMENT ONLY RESIDENTIAL BUILDING 10456 1229 CLAY AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.832692 -73.910457 (40.832691765345125, -73.9104574878717)
101 31708483 10/08/2015 01:12:31 PM 10/11/2015 12:40:33 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 10029 1908 3 AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.791142 -73.945002 (40.79114185049376, -73.94500215033766)
102 31715268 10/08/2015 10:23:57 PM 10/11/2015 10:00:00 AM HPD Department of Housing Preservation and Develop... ELECTRIC NO LIGHTING RESIDENTIAL BUILDING 10453 2015 CRESTON AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.852033 -73.905487 (40.8520325101027, -73.90548654524089)
138 31708315 10/08/2015 10:09:52 AM 10/11/2015 08:41:38 AM HPD Department of Housing Preservation and Develop... FLOORING/STAIRS FLOOR RESIDENTIAL BUILDING 10035 2310 1 AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.797677 -73.934169 (40.79767686381545, -73.93416874100691)
182 31713211 10/08/2015 10:23:57 PM 10/11/2015 09:59:59 AM HPD Department of Housing Preservation and Develop... ELECTRIC NO LIGHTING RESIDENTIAL BUILDING 10453 2015 CRESTON AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.852033 -73.905487 (40.8520325101027, -73.90548654524089)
186 31650350 09/30/2015 10:45:00 AM 10/11/2015 01:01:43 PM HPD Department of Housing Preservation and Develop... UNSANITARY CONDITION MOLD RESIDENTIAL BUILDING 10473 825 BOYNTON AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.820139 -73.876260 (40.820138740518026, -73.87625959537276)
190 31786412 10/19/2015 08:33:37 AM 11/02/2015 10:24:24 AM HPD Department of Housing Preservation and Develop... WATER LEAK DAMP SPOT RESIDENTIAL BUILDING 11203 374 EAST 49 STREET ... NaN NaN NaN NaN NaN NaN NaN 40.652807 -73.931519 (40.65280703038938, -73.9315186685526)
194 31796961 10/19/2015 02:11:39 AM 10/20/2015 06:33:03 PM HPD Department of Housing Preservation and Develop... PAINT/PLASTER WALL RESIDENTIAL BUILDING 10472 1035 ELDER AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.824694 -73.878278 (40.82469437887579, -73.8782781366498)
195 31793985 10/19/2015 09:00:17 PM 10/22/2015 05:21:28 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11203 5417 KINGS HIGHWAY ... NaN NaN NaN NaN NaN NaN NaN 40.641031 -73.925578 (40.64103095778472, -73.92557815868905)
231 31933333 11/07/2015 10:18:46 PM 11/12/2015 11:08:54 AM HPD Department of Housing Preservation and Develop... PLUMBING BASIN/SINK RESIDENTIAL BUILDING 10032 3851 BROADWAY ... NaN NaN NaN NaN NaN NaN NaN 40.836272 -73.943274 (40.836272466705225, -73.9432735657598)
234 31792584 10/19/2015 10:07:55 PM 10/23/2015 09:52:57 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11423 102-44 184 STREET ... NaN NaN NaN NaN NaN NaN NaN 40.706932 -73.773379 (40.7069316327699, -73.7733791984795)
237 31645382 09/30/2015 12:34:50 PM 10/11/2015 08:21:41 AM HPD Department of Housing Preservation and Develop... DOOR/WINDOW DOOR RESIDENTIAL BUILDING 10011 419 WEST 21 STREET ... NaN NaN NaN NaN NaN NaN NaN 40.745548 -74.003053 (40.745548328096355, -74.00305314436002)
239 31789559 10/19/2015 02:03:29 PM 11/02/2015 11:29:24 AM HPD Department of Housing Preservation and Develop... FLOORING/STAIRS FLOOR RESIDENTIAL BUILDING 10453 1725 ANDREWS AVENUE SOUTH ... NaN NaN NaN NaN NaN NaN NaN 40.850137 -73.917584 (40.850136961509634, -73.91758367042492)
241 31790022 10/19/2015 09:07:58 PM 10/24/2015 04:14:40 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11230 1317 EAST 14 STREET ... NaN NaN NaN NaN NaN NaN NaN 40.617141 -73.960807 (40.617141244632286, -73.96080690570872)
242 31481296 09/07/2015 11:06:58 AM 10/19/2015 08:44:53 AM HPD Department of Housing Preservation and Develop... PLUMBING BASIN/SINK RESIDENTIAL BUILDING 10474 820 MANIDA STREET ... NaN NaN NaN NaN NaN NaN NaN 40.817215 -73.889441 (40.817215281199104, -73.88944093954447)
243 31789673 10/19/2015 03:26:49 AM 10/22/2015 01:11:33 AM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER APARTMENT ONLY RESIDENTIAL BUILDING 10456 1105 COLLEGE AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.830743 -73.914583 (40.8307434030938, -73.91458315961115)
248 31607830 09/24/2015 02:43:12 PM 10/13/2015 08:40:04 AM HPD Department of Housing Preservation and Develop... FLOORING/STAIRS FLOOR RESIDENTIAL BUILDING 10453 2081 MORRIS AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.853871 -73.904963 (40.853871032220624, -73.90496340190745)
249 31610913 09/24/2015 04:58:07 PM 10/13/2015 12:53:46 PM HPD Department of Housing Preservation and Develop... PAINT/PLASTER WALL RESIDENTIAL BUILDING 11435 85-66 150 STREET ... NaN NaN NaN NaN NaN NaN NaN 40.709844 -73.808390 (40.70984430633433, -73.80838960982769)
251 31609502 09/24/2015 08:18:36 AM 10/13/2015 08:40:23 AM HPD Department of Housing Preservation and Develop... UNSANITARY CONDITION MOLD RESIDENTIAL BUILDING 11216 1232 PACIFIC STREET ... NaN NaN NaN NaN NaN NaN NaN 40.677715 -73.950915 (40.677714828945554, -73.95091456117359)
275 31941672 11/08/2015 04:23:51 PM 11/09/2015 10:57:58 AM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 10014 326 BLEECKER STREET ... NaN NaN NaN NaN NaN NaN NaN 40.733260 -74.004207 (40.73326003789622, -74.0042072220039)
278 31604751 09/24/2015 02:04:08 PM 10/13/2015 08:40:25 AM HPD Department of Housing Preservation and Develop... APPLIANCE REFRIGERATOR RESIDENTIAL BUILDING 11209 7501 4 AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.630721 -74.025118 (40.63072091714361, -74.02511808192473)
279 31605034 09/24/2015 04:24:35 PM 10/13/2015 08:40:26 AM HPD Department of Housing Preservation and Develop... ELECTRIC NO LIGHTING RESIDENTIAL BUILDING 11212 367 EAST 96 STREET ... NaN NaN NaN NaN NaN NaN NaN 40.658337 -73.918372 (40.658337422179216, -73.9183720745339)
284 31788714 10/19/2015 11:12:15 AM 10/27/2015 11:30:30 AM HPD Department of Housing Preservation and Develop... PLUMBING BASIN/SINK RESIDENTIAL BUILDING 10458 2980 VALENTINE AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.871881 -73.886143 (40.87188118407785, -73.88614285307307)
287 31940754 11/08/2015 02:57:16 PM 11/13/2015 01:40:04 PM HPD Department of Housing Preservation and Develop... WATER LEAK SLOW LEAK RESIDENTIAL BUILDING 10031 1627 AMSTERDAM AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.822376 -73.949684 (40.822376208524275, -73.94968418530969)
288 31792913 10/19/2015 06:49:12 AM 10/20/2015 08:31:36 AM HPD Department of Housing Preservation and Develop... PLUMBING RADIATOR RESIDENTIAL BUILDING 10031 613 WEST 140 STREET ... NaN NaN NaN NaN NaN NaN NaN 40.823506 -73.953322 (40.82350581714176, -73.95332176937653)
290 31791435 10/19/2015 01:44:46 PM 10/22/2015 06:55:45 AM HPD Department of Housing Preservation and Develop... PAINT/PLASTER CEILING RESIDENTIAL BUILDING 11220 6301 4 AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.639050 -74.020275 (40.63904955864053, -74.02027496948601)
294 31787270 10/19/2015 11:16:13 PM 10/25/2015 06:10:46 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11204 6402 24 AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.611675 -73.976488 (40.61167514809308, -73.97648823043437)
298 31723740 10/10/2015 01:24:53 AM 10/16/2015 12:40:16 PM HPD Department of Housing Preservation and Develop... UNSANITARY CONDITION PESTS RESIDENTIAL BUILDING 10463 3804 BAILEY AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.884240 -73.897662 (40.88424034482077, -73.89766177595318)
333 31937786 11/08/2015 01:17:30 PM 11/20/2015 09:43:06 PM HPD Department of Housing Preservation and Develop... UNSANITARY CONDITION PESTS RESIDENTIAL BUILDING 11433 108-51 GUY R BREWER BOULEVARD ... NaN NaN NaN NaN NaN NaN NaN 40.695766 -73.790648 (40.69576565822967, -73.79064773889174)
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2011888 32301100 12/30/2015 01:54:52 AM 12/30/2015 10:42:46 AM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11374 99-44 62 AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.735099 -73.857979 (40.73509935689471, -73.8579788213209)
2011890 32301120 12/30/2015 09:06:00 AM 12/30/2015 09:41:02 PM HPD Department of Housing Preservation and Develop... PLUMBING WATER SUPPLY RESIDENTIAL BUILDING 10468 2820 SEDGWICK AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.872780 -73.902040 (40.87277956585497, -73.90204010051565)
2011902 32301183 12/30/2015 09:45:29 AM 12/30/2015 08:02:56 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11221 279 EVERGREEN AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.695152 -73.925500 (40.69515244020965, -73.92549971599507)
2012060 32301824 12/30/2015 02:16:59 AM 12/30/2015 09:49:06 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER APARTMENT ONLY RESIDENTIAL BUILDING 11207 529 SNEDIKER AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.661835 -73.899055 (40.66183541246747, -73.89905546915963)
2012065 32301878 12/30/2015 04:17:01 PM 12/30/2015 04:19:32 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER APARTMENT ONLY RESIDENTIAL BUILDING 11226 1487 NOSTRAND AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.650041 -73.949483 (40.65004134792918, -73.94948260889885)
2012069 32301918 12/30/2015 07:03:28 PM 12/30/2015 10:59:11 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER APARTMENT ONLY RESIDENTIAL BUILDING 11221 1272 JEFFERSON AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.692146 -73.912417 (40.692145938896864, -73.91241679704119)
2012080 32301938 12/30/2015 02:18:52 PM 12/30/2015 03:40:06 PM HPD Department of Housing Preservation and Develop... GENERAL COOKING GAS RESIDENTIAL BUILDING 11211 218 SOUTH 3 STREET ... NaN NaN NaN NaN NaN NaN NaN 40.711210 -73.958973 (40.71120965026345, -73.95897331500413)
2012081 32301939 12/30/2015 07:21:52 PM 12/30/2015 09:21:16 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11229 2626 KINGS HIGHWAY ... NaN NaN NaN NaN NaN NaN NaN 40.613982 -73.947756 (40.613982286197604, -73.94775581793884)
2012084 32302004 12/30/2015 12:43:48 PM 12/30/2015 05:47:10 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11213 1170 LINCOLN PLACE ... NaN NaN NaN NaN NaN NaN NaN 40.670103 -73.937835 (40.67010273131729, -73.93783460798147)
2012090 32302036 12/30/2015 02:39:36 AM 12/30/2015 10:42:46 AM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11374 99-44 62 AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.735099 -73.857979 (40.73509935689471, -73.8579788213209)
2012095 32302105 12/30/2015 12:48:25 PM 12/30/2015 05:42:49 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11209 7420 RIDGE BOULEVARD ... NaN NaN NaN NaN NaN NaN NaN 40.632592 -74.030285 (40.632591618048004, -74.03028521466096)
2012280 32302896 12/30/2015 07:10:13 AM 12/30/2015 09:03:42 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER APARTMENT ONLY RESIDENTIAL BUILDING 11232 4114 9 AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.644692 -73.996418 (40.64469182424792, -73.99641815821968)
2012281 32302897 12/30/2015 02:20:59 PM 12/30/2015 03:40:06 PM HPD Department of Housing Preservation and Develop... GENERAL COOKING GAS RESIDENTIAL BUILDING 11211 218 SOUTH 3 STREET ... NaN NaN NaN NaN NaN NaN NaN 40.711210 -73.958973 (40.71120965026345, -73.95897331500413)
2012282 32302906 12/30/2015 12:43:12 PM 12/30/2015 09:57:42 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11214 8735 BAY PARKWAY ... NaN NaN NaN NaN NaN NaN NaN 40.599257 -73.996590 (40.5992573007694, -73.99658984305856)
2012294 32303000 12/30/2015 08:37:01 AM 12/30/2015 01:25:05 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11216 1316 PACIFIC STREET ... NaN NaN NaN NaN NaN NaN NaN 40.677516 -73.947414 (40.67751565855699, -73.94741402291248)
2012504 32303772 12/30/2015 12:48:07 PM 12/30/2015 05:47:10 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER APARTMENT ONLY RESIDENTIAL BUILDING 11216 820 NOSTRAND AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.670578 -73.950444 (40.67057821068635, -73.95044397157412)
2012528 32303994 12/30/2015 12:50:45 PM 12/30/2015 09:40:02 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11377 72-10 41 AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.744999 -73.892968 (40.74499909172425, -73.89296757512533)
2012536 32304047 12/30/2015 08:16:20 AM 12/30/2015 09:14:59 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11226 327 EAST 19 STREET ... NaN NaN NaN NaN NaN NaN NaN 40.642193 -73.960727 (40.64219290930606, -73.96072733113357)
2012539 32304059 12/30/2015 03:34:12 PM 12/30/2015 10:59:11 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11221 1013 PUTNAM AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.687453 -73.920352 (40.68745265640268, -73.92035206084482)
2012726 32304744 12/30/2015 12:27:13 AM 12/30/2015 09:40:05 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER APARTMENT ONLY RESIDENTIAL BUILDING 11377 39-50 60 STREET ... NaN NaN NaN NaN NaN NaN NaN 40.746093 -73.904190 (40.746093150327205, -73.90418965073997)
2012732 32304776 12/30/2015 04:31:57 AM 12/30/2015 02:28:49 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11219 902 41 STREET ... NaN NaN NaN NaN NaN NaN NaN 40.644620 -73.995943 (40.64462044405135, -73.9959425055027)
2012737 32304807 12/30/2015 12:05:30 PM 12/30/2015 05:13:01 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER APARTMENT ONLY RESIDENTIAL BUILDING 10463 3025 GODWIN TERRACE ... NaN NaN NaN NaN NaN NaN NaN 40.878330 -73.906574 (40.87833035031833, -73.90657377788568)
2012739 32304829 12/30/2015 09:52:52 AM 12/30/2015 06:00:31 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11225 250 CROWN STREET ... NaN NaN NaN NaN NaN NaN NaN 40.666344 -73.952019 (40.66634368666201, -73.95201873752808)
2012740 32304841 12/30/2015 08:26:23 AM 12/30/2015 06:20:05 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11224 3601 NEPTUNE AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.576997 -74.002322 (40.576996995912054, -74.00232187767683)
2012742 32304845 12/30/2015 07:20:22 AM 12/30/2015 09:58:59 AM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11691 252 BEACH 14 STREET ... NaN NaN NaN NaN NaN NaN NaN 40.597101 -73.748175 (40.59710124812239, -73.74817471674652)
2012743 32304858 12/30/2015 01:33:20 AM 01/07/2016 11:28:48 AM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11203 462 EAST 42 STREET ... NaN NaN NaN NaN NaN NaN NaN 40.644225 -73.937325 (40.64422465668857, -73.93732540925855)
2012749 32304886 12/30/2015 10:48:16 AM 12/30/2015 08:58:06 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11210 1368 NEW YORK AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.639596 -73.945473 (40.63959560983165, -73.9454729623113)
2012756 32304931 12/30/2015 10:58:18 AM 12/30/2015 08:02:56 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11221 279 EVERGREEN AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.695152 -73.925500 (40.69515244020965, -73.92549971599507)
2012757 32304937 12/30/2015 06:48:13 AM 12/30/2015 09:21:17 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11234 3857 KINGS HIGHWAY ... NaN NaN NaN NaN NaN NaN NaN 40.622952 -73.935897 (40.6229517578704, -73.93589726426204)
2012758 32304938 12/30/2015 01:02:21 PM 12/30/2015 09:40:02 PM HPD Department of Housing Preservation and Develop... HEAT/HOT WATER ENTIRE BUILDING RESIDENTIAL BUILDING 11377 72-10 41 AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.744999 -73.892968 (40.74499909172425, -73.89296757512533)

616226 rows × 53 columns


In [2]:
# Get all noise complaints
noise_cats = ['Noise - Vehicle','Noise','Noise - Residential','Noise - Street/Sidewalk','Noise - Commercial']
noise1 = quality[quality['Complaint Type'] == 'Noise - Vehicle']
noise2 = quality[quality['Complaint Type'] == 'Noise']
noise3 = quality[quality['Complaint Type'] == 'Noise - Residential']
noise4 = quality[quality['Complaint Type'] == 'Noise - Street/Sidewalk']
noise5 = quality[quality['Complaint Type'] == 'Noise - Commercial']

In [3]:
# Combine the different noise complaints
# frames = [noise1,noise2,noise3,noise4,noise5]
noise = pd.concat([noise1,noise2,noise3,noise4,noise5])
noise = noise.reset_index(drop=True)

In [16]:
# noise.to_csv('noise-complaints.csv')
# food.to_csv('food-complaints.csv')
# homeless.to_csv('homeless-complaints.csv')
# neighbourhood.to_csv('neighbourhood-complaints.csv')
sanitation.to_csv('sanitation-complaints.csv')

In [5]:
# Get  food complaints
food_cats = ['Food Poisoning', 'Food Establishment']
foodPosioning = quality[quality['Complaint Type'] == 'Food Poisoning']
foodEstablishment = quality[quality['Complaint Type'] == 'Food Establishment']
frames = [foodPosioning,foodEstablishment]
food = pd.concat(frames)
food = food.reset_index(drop=True)

In [13]:
# Sort by Borough 
brooklynFood = food[food['Borough'] == "BROOKLYN"]
queensFood = food[food['Borough'] == "QUEENS"] 
manhattanFood = food[food['Borough'] == "MANHATTAN"] 
bronxFood = food[food['Borough'] == "BRONX"] 
statenIslandFood = food[food['Borough'] == "STATEN ISLAND"]

In [ ]:
#food

In [7]:
# Homeless People
homeless_cats = ['Homeless Person Assistance', 'Homeless Encampment']
homelessPerson = quality[quality['Complaint Type'] == 'Homeless Person Assistance'] 
HomelessEncampment = quality[quality['Complaint Type'] == 'Homeless Encampment'] 
frame = [homelessPerson,HomelessEncampment]
homeless = pd.concat(frame)
homeless = homeless.reset_index(drop=True)

In [ ]:
#homeless

In [12]:
# Neighbourhood Condition
neighbourhood_cats = ['Street Condition', 'Street Light Condition', 'Sweeping/Inadequate', 'Graffiti', 'Derelict Vehicle']

streetRoad  = quality[quality['Complaint Type'] == 'Street Condition']
streetLight  = quality[quality['Complaint Type'] == 'Street Light Condition']
sweeping = quality[quality['Complaint Type'] == 'Sweeping/Inadequate']
graffiti = quality[quality['Complaint Type'] == 'Graffiti']
derelictV = quality[quality['Complaint Type'] == 'Derelict Vehicle']

frames = [streetRoad,streetLight,derelictV,sweeping,graffiti]
neighbourhood = pd.concat(frames)
neighbourhood = neighbourhood.reset_index(drop=True)

In [15]:
# Sanitation
sanitation_cats = ['Rodent', 'Dirty Conditions','Sanitation Condition', 'Sewer']

rodent = quality[quality['Complaint Type'] == 'Rodent']
dirty = quality[quality['Complaint Type'] == 'Dirty Conditions']
sanitationC = quality[quality['Complaint Type'] == 'Sanitation Condition']
sewer = quality[quality['Complaint Type'] == 'Sewer']

frames = [rodent,dirty,sanitationC,sewer]
sanitation = pd.concat(frames)
sanitation = sanitation.reset_index(drop=True)

In [ ]:
neighbourhood

In [18]:
geo_data = {'lat':awer['Latitude'].values, 'lon':awer['Longitude'].values}
#geo_data2 = {'lat':sanitation['Latitude'].values, 'lon':sanitation['Longitude'].values}
#geo_data3 = {'lat':neighbourhood['Latitude'].values, 'lon':neighbourhood['Longitude'].values}
geo_data


Out[18]:
{'lat': array([ 40.84149732,  40.83269177,  40.79114185, ...,  40.69515244,
         40.62295176,  40.74499909]),
 'lon': array([-73.91113593, -73.91045749, -73.94500215, ..., -73.92549972,
        -73.93589726, -73.89296758])}

In [19]:
import geoplotlib as gp
from geoplotlib.utils import BoundingBox

 # Prepare data for bounding box
max_lat = max(geo_data['lat'])
print max_lat
min_lon = min(geo_data['lon'])
    #print min_lon
min_lat = min(geo_data['lat'])
    #print min_lat
max_lon = max(geo_data['lon'])
    #print max_lon
        
    
    # Create and set bounding box for map of San Francisko
bbox = BoundingBox(north=max_lat, west=min_lon, south=min_lat, east=max_lon)
gp.set_bbox(bbox)
gp.kde(geo_data,5)
gp.show()


40.9115873206
('smallest non-zero count', 1.2896615779891282e-08)
('max count:', 106.35632446805016)

In [20]:
# Prepare data for bounding box
max_lat2 = max(geo_data2['lat'])
   
min_lon2 = min(geo_data2['lon'])
    #print min_lon
min_lat2 = min(geo_data2['lat'])
    #print min_lat
max_lon2 = max(geo_data2['lon'])
    #print max_lon
        
    
    # Create and set bounding box for map of San Francisko
bbox = BoundingBox(north=max_lat2, west=min_lon2, south=min_lat2, east=max_lon2)
gp.set_bbox(bbox)
gp.kde(geo_data2,5)
gp.show()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-20-3fb1a91c5826> in <module>()
      1 # Prepare data for bounding box
----> 2 max_lat2 = max(geo_data2['lat'])
      3 
      4 min_lon2 = min(geo_data2['lon'])
      5    #print min_lon

NameError: name 'geo_data2' is not defined

In [21]:
import geoplotlib as gp
from geoplotlib.utils import BoundingBox

 # Prepare data for bounding box
max_lat3 = max(geo_data['lat'])
   
min_lon3 = min(geo_data['lon'])
    #print min_lon
min_lat3 = min(geo_data['lat'])
    #print min_lat
max_lon3 = max(geo_data['lon'])
    #print max_lon
        
    
    # Create and set bounding box for map of San Francisko
bbox = BoundingBox(north=max_lat3, west=min_lon3, south=min_lat3, east=max_lon3)
gp.set_bbox(bbox)
gp.kde(geo_data3,3)
gp.show()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-21-bb3d7813e4bc> in <module>()
     16 bbox = BoundingBox(north=max_lat3, west=min_lon3, south=min_lat3, east=max_lon3)
     17 gp.set_bbox(bbox)
---> 18 gp.kde(geo_data3,3)
     19 gp.show()

NameError: name 'geo_data3' is not defined

In [33]:
# accepted_cats = dict({'PROSTITUTION': 1,'DRUG/NARCOTIC': 2,'DRIVING UNDER THE INFLUENCE': 3})
# from collections import Counter
# LIMIT = 4000
# cc = Counter([])
# geo_data_for_plotting = {'Category': [], 'lat': [], 'lon': []}
# test_data = []
# for (i, item) in enumerate(data['Category']):
#     if accepted_cats.has_key(item):
#         #test_data.append({'Category': item, 'lat': data['Y'][i], 'lon': data['X'][i]})
# #         if cc[item] >= LIMIT/len(accepted_cats):
# #             continue
        
#         cc.update([item])
#         geo_data_for_plotting['Category'].append(item)
#         geo_data_for_plotting['lat'].append(data['Y'][i])
#         geo_data_for_plotting['lon'].append(data['X'][i])
#         test_data.append([accepted_cats[item], data['Y'][i], data['X'][i]])

In [62]:
def complaint_to_list(complaint):
    ctl = list(awer['Complaint Type'].value_counts().keys())
    return ctl.index(complaint)
map(complaint_to_list, awer['Complaint Type'])


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-62-c2463e8f81a3> in <module>()
      2     ctl = list(awer['Complaint Type'].value_counts().keys())
      3     return ctl.index(complaint)
----> 4 map(complaint_to_list, awer['Complaint Type'])

<ipython-input-62-c2463e8f81a3> in complaint_to_list(complaint)
      1 def complaint_to_list(complaint):
----> 2     ctl = list(awer['Complaint Type'].value_counts().keys())
      3     return ctl.index(complaint)
      4 map(complaint_to_list, awer['Complaint Type'])

/usr/lib64/python2.7/site-packages/pandas/core/base.pyc in value_counts(self, normalize, sort, ascending, bins, dropna)
    949         from pandas.core.algorithms import value_counts
    950         result = value_counts(self, sort=sort, ascending=ascending,
--> 951                               normalize=normalize, bins=bins, dropna=dropna)
    952         return result
    953 

/usr/lib64/python2.7/site-packages/pandas/core/algorithms.pyc in value_counts(values, sort, ascending, normalize, bins, dropna)
    376     else:
    377         # ndarray path. pass original to handle DatetimeTzBlock
--> 378         keys, counts = _value_counts_arraylike(values, dropna=dropna)
    379 
    380         from pandas import Index, Series

/usr/lib64/python2.7/site-packages/pandas/core/algorithms.pyc in _value_counts_arraylike(values, dropna)
    401     is_datetimetz_type = is_datetimetz(values)
    402     is_period_type = (is_period_dtype(values) or
--> 403                       is_period_arraylike(values))
    404 
    405     orig = values

/usr/lib64/python2.7/site-packages/pandas/types/common.pyc in is_period_arraylike(arr)
    114         return True
    115     elif isinstance(arr, (np.ndarray, ABCSeries)):
--> 116         return arr.dtype == object and lib.infer_dtype(arr) == 'period'
    117     return getattr(arr, 'inferred_type', None) == 'period'
    118 

KeyboardInterrupt: 

In [63]:
awer.to_csv('housing-dept.csv')

In [ ]:
import numpy as np
import pylab as pl
from sklearn import neighbors, datasets

X = np.array(zip(geo_data.lat,geo_data.lon))
Y = 

h = .02 # step size in the mesh

knn=neighbors.KNeighborsClassifier(n_neighbors=5)

# we create an instance of Neighbours Classifier and fit the data.
knn.fit(X, Y)

# Plot the decision boundary. For that, we will asign a color to each
# point in the mesh [x_min, m_max]x[y_min, y_max].
x_min, x_max = X[:,0].min() - .5, X[:,0].max() + .5
y_min, y_max = X[:,1].min() - .5, X[:,1].max() + .5
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
Z = knn.predict(np.c_[xx.ravel(), yy.ravel()])

# Put the result into a color plot
Z = Z.reshape(xx.shape)
pl.figure(1, figsize=(4, 3))
pl.set_cmap(pl.cm.Paired)
pl.pcolormesh(xx, yy, Z)

# Plot also the training points
#pl.scatter(X[:,0], X[:,1],c=Y )
pl.xlabel('Sepal length')
pl.ylabel('Sepal width')

pl.xlim(xx.min(), xx.max())
pl.ylim(yy.min(), yy.max())
pl.xticks(())
pl.yticks(())

pl.show()