0% found this document useful (0 votes)
62 views

Serv NYC Project

Uploaded by

Anshu Baidya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Serv NYC Project

Uploaded by

Anshu Baidya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

In [24]:

#import libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

In [2]:

#import a 311 NYC service request

In [6]:

serv_nyc=pd.read_csv("C:\\ Users\\ Apurba baidya\\ Desktop\\ 311_Service_Requests_from_2010_


to_Present.csv",low_memory=False)

In [8]:

serv_nyc.head()

Out[8]:

Unique Created Closed Agency Incident Incident


Agency Complaint Type Descriptor Location Type ... Hig
Key Date Date Name Zip Address

12/31/2015 New York 71


01-01- Noise - Loud
0 32310363 11:59:45 NYPD City Police Street/Sidewalk 10034.0 VERMILYEA ...
16 0:55 Street/Sidewalk Music/Party
PM Department AVENUE

12/31/2015 New York


01-01- Blocked 27-07 23
1 32309934 11:59:44 NYPD City Police No Access Street/Sidewalk 11105.0 ...
16 1:26 Driveway AVENUE
PM Department

12/31/2015 New York 2897


01-01- Blocked
2 32309159 11:59:29 NYPD City Police No Access Street/Sidewalk 10458.0 VALENTINE ...
16 4:51 Driveway
PM Department AVENUE

12/31/2015 New York Commercial 2940


01-01-
3 32305098 11:57:46 NYPD City Police Illegal Parking Overnight Street/Sidewalk 10461.0 BAISLEY ...
16 7:43
PM Department Parking AVENUE

12/31/2015 New York


01-01- Blocked 87-14 57
4 32306529 11:56:58 NYPD City Police Illegal Parking Street/Sidewalk 11373.0 ...
16 3:24 Sidewalk ROAD
PM Department

5 rows × 53 columns

In [9]:
serv_nyc.tail()
Out[9]:

Unique Created Closed Agency Complaint Incident Inciden


Agency Descriptor Location Type
Key Date Date Name Type Zip Addres

03/29/2015 New York


Noise - Loud CRESCEN
300693 30281872 12:33:41 NaN NYPD City Police Club/Bar/Restaurant NaN
Commercial Music/Party AVENUE
AM Department

03/29/2015 03/29/2015 New York


Blocked Partial 100-17 8
300694 30281230 12:33:28 02:33:59 NYPD City Police Street/Sidewalk 11418.0
Driveway Access AVENUE
AM AM Department

03/29/2015 03/29/2015 New York 16


Noise - Loud
300695 30283424 12:33:03 03:40:20 NYPD City Police Club/Bar/Restaurant 11206.0 THROOP
Commercial Music/Party
AM AM Department AVENUE
03/29/2015 03/29/2015 New York 3151 EAS
Unique Created Closed Agency Noise -
Complaint Loud Incident Inciden
300696 30280004 12:33:02 04:38:35 NYPD
Agency City Police Descriptor Club/Bar/Restaurant
Location Type 10461.0 TREMON
Key Date Date Name Commercial
Type Music/Party Zip Addres
AM AM Department AVENUE

03/29/2015 03/29/2015 New York


Noise - Loud 251 WEST
300697 30281825 12:33:01 04:41:50 NYPD City Police Store/Commercial 10036.0
Commercial Music/Party 48 STREE
AM AM Department

5 rows × 53 columns

In [10]:
# understanding patterns of the dataset
serv_nyc

Out[10]:

Unique Created Closed Agency Incident Inc


Agency Complaint Type Descriptor Location Type
Key Date Date Name Zip Ad

12/31/2015 New York


01-01-16 Noise - Loud
0 32310363 11:59:45 NYPD City Police Street/Sidewalk 10034.0 VERMI
0:55 Street/Sidewalk Music/Party
PM Department AV

12/31/2015 New York


01-01-16 Blocked 27-
1 32309934 11:59:44 NYPD City Police No Access Street/Sidewalk 11105.0
1:26 Driveway AV
PM Department

12/31/2015 New York


01-01-16 Blocked
2 32309159 11:59:29 NYPD City Police No Access Street/Sidewalk 10458.0 VALEN
4:51 Driveway
PM Department AV

12/31/2015 New York Commercial


01-01-16
3 32305098 11:57:46 NYPD City Police Illegal Parking Overnight Street/Sidewalk 10461.0 BAI
7:43
PM Department Parking AV

12/31/2015 New York


01-01-16 Blocked 87-
4 32306529 11:56:58 NYPD City Police Illegal Parking Street/Sidewalk 11373.0
3:24 Sidewalk
PM Department

... ... ... ... ... ... ... ... ... ...

03/29/2015 New York


Noise - Loud CRES
300693 30281872 12:33:41 NaN NYPD City Police Club/Bar/Restaurant NaN
Commercial Music/Party AV
AM Department

03/29/2015 03/29/2015 New York


Blocked Partial 100-
300694 30281230 12:33:28 02:33:59 NYPD City Police Street/Sidewalk 11418.0
Driveway Access AV
AM AM Department

03/29/2015 03/29/2015 New York


Noise - Loud
300695 30283424 12:33:03 03:40:20 NYPD City Police Club/Bar/Restaurant 11206.0 THR
Commercial Music/Party
AM AM Department AV

03/29/2015 03/29/2015 New York 3151


Noise - Loud
300696 30280004 12:33:02 04:38:35 NYPD City Police Club/Bar/Restaurant 10461.0 TREM
Commercial Music/Party
AM AM Department AV

03/29/2015 03/29/2015 New York


Noise - Loud 251 W
300697 30281825 12:33:01 04:41:50 NYPD City Police Store/Commercial 10036.0
Commercial Music/Party 48 ST
AM AM Department

300698 rows × 53 columns

In [11]:
# getting the information
serv_nyc.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 300698 entries, 0 to 300697
Data columns (total 53 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Unique Key 300698 non-null int64
0 Unique Key 300698 non-null int64
1 Created Date 300698 non-null object
2 Closed Date 298534 non-null object
3 Agency 300698 non-null object
4 Agency Name 300698 non-null object
5 Complaint Type 300698 non-null object
6 Descriptor 294784 non-null object
7 Location Type 300567 non-null object
8 Incident Zip 298083 non-null float64
9 Incident Address 256288 non-null object
10 Street Name 256288 non-null object
11 Cross Street 1 251419 non-null object
12 Cross Street 2 250919 non-null object
13 Intersection Street 1 43858 non-null object
14 Intersection Street 2 43362 non-null object
15 Address Type 297883 non-null object
16 City 298084 non-null object
17 Landmark 349 non-null object
18 Facility Type 298527 non-null object
19 Status 300698 non-null object
20 Due Date 300695 non-null object
21 Resolution Description 300698 non-null object
22 Resolution Action Updated Date 298511 non-null object
23 Community Board 300698 non-null object
24 Borough 300698 non-null object
25 X Coordinate (State Plane) 297158 non-null float64
26 Y Coordinate (State Plane) 297158 non-null float64
27 Park Facility Name 300698 non-null object
28 Park Borough 300698 non-null object
29 School Name 300698 non-null object
30 School Number 300698 non-null object
31 School Region 300697 non-null object
32 School Code 300697 non-null object
33 School Phone Number 300698 non-null object
34 School Address 300698 non-null object
35 School City 300698 non-null object
36 School State 300698 non-null object
37 School Zip 300697 non-null object
38 School Not Found 300698 non-null object
39 School or Citywide Complaint 0 non-null float64
40 Vehicle Type 0 non-null float64
41 Taxi Company Borough 0 non-null float64
42 Taxi Pick Up Location 0 non-null float64
43 Bridge Highway Name 243 non-null object
44 Bridge Highway Direction 243 non-null object
45 Road Ramp 213 non-null object
46 Bridge Highway Segment 213 non-null object
47 Garage Lot Name 0 non-null float64
48 Ferry Direction 1 non-null object
49 Ferry Terminal Name 2 non-null object
50 Latitude 297158 non-null float64
51 Longitude 297158 non-null float64
52 Location 297158 non-null object
dtypes: float64(10), int64(1), object(42)
memory usage: 121.6+ MB

In [12]:

#Drop all null columns


serv_nyc1=serv_nyc.drop(["Garage Lot Name","Taxi Pick Up Location","Taxi Company Borough"
,"Vehicle Type","School or Citywide Complaint"],axis=1)
serv_nyc1.head()
Out[12]:

Sch
Unique Created Closed Agency Incident Incident
Agency Complaint Type Descriptor Location Type ...
Key Date Date Name Zip Address
Fo

12/31/2015 New York 71


01-01- Noise - Loud
0 32310363 11:59:45 NYPD City Police Street/Sidewalk 10034.0 VERMILYEA ...
16 0:55 Street/Sidewalk Music/Party
PM Department AVENUE
12/31/2015 New York Sch
Unique Created Closed
01-01- Agency Blocked Incident 27-07
Incident
23
1 32309934 11:59:44 Agency
NYPD City Police Complaint Type No
Descriptor
Access Street/Sidewalk
Location Type 11105.0 ...
Key Date 16Date
1:26 Name Driveway Zip AVENUE
Address
PM Department Fo

12/31/2015 New York 2897


01-01- Blocked
2 32309159 11:59:29 NYPD City Police No Access Street/Sidewalk 10458.0 VALENTINE ...
16 4:51 Driveway
PM Department AVENUE

12/31/2015 New York Commercial 2940


01-01-
3 32305098 11:57:46 NYPD City Police Illegal Parking Overnight Street/Sidewalk 10461.0 BAISLEY ...
16 7:43
PM Department Parking AVENUE

12/31/2015 New York


01-01- Blocked 87-14 57
4 32306529 11:56:58 NYPD City Police Illegal Parking Street/Sidewalk 11373.0 ...
16 3:24 Sidewalk ROAD
PM Department

5 rows × 48 columns

In [14]:
# understanding the dataset getting mean,standard deviation,percentile, min, max value
serv_nyc1.describe()
Out[14]:

Unique Key Incident Zip X Coordinate (State Plane) Y Coordinate (State Plane) Latitude Longitude

count 3.006980e+05 298083.000000 2.971580e+05 297158.000000 297158.000000 297158.000000

mean 3.130054e+07 10848.888645 1.004854e+06 203754.534416 40.725885 -73.925630

std 5.738547e+05 583.182081 2.175338e+04 29880.183529 0.082012 0.078454

min 3.027948e+07 83.000000 9.133570e+05 121219.000000 40.499135 -74.254937

25% 3.080118e+07 10310.000000 9.919752e+05 183343.000000 40.669796 -73.972142

50% 3.130436e+07 11208.000000 1.003158e+06 201110.500000 40.718661 -73.931781

75% 3.178446e+07 11238.000000 1.018372e+06 224125.250000 40.781840 -73.876805

max 3.231065e+07 11697.000000 1.067173e+06 271876.000000 40.912869 -73.700760

In [15]:
serv_nyc1.index.values
Out[15]:
array([ 0, 1, 2, ..., 300695, 300696, 300697], dtype=int64)

In [16]:
serv_nyc1.columns.values
Out[16]:
array(['Unique Key', 'Created Date', 'Closed Date', 'Agency',
'Agency Name', 'Complaint Type', 'Descriptor', 'Location Type',
'Incident Zip', 'Incident Address', 'Street Name',
'Cross Street 1', 'Cross Street 2', 'Intersection Street 1',
'Intersection Street 2', 'Address Type', 'City', 'Landmark',
'Facility Type', 'Status', 'Due Date', 'Resolution Description',
'Resolution Action Updated Date', 'Community Board', 'Borough',
'X Coordinate (State Plane)', 'Y Coordinate (State Plane)',
'Park Facility Name', 'Park Borough', 'School Name',
'School Number', 'School Region', 'School Code',
'School Phone Number', 'School Address', 'School City',
'School State', 'School Zip', 'School Not Found',
'Bridge Highway Name', 'Bridge Highway Direction', 'Road Ramp',
'Bridge Highway Segment', 'Ferry Direction', 'Ferry Terminal Name',
'Latitude', 'Longitude', 'Location'], dtype=object)

In [17]:
serv_nyc1.info
Out[17]:
<bound method DataFrame.info of Unique Key Created Date C
losed Date Agency \
0 32310363 12/31/2015 11:59:45 PM 01-01-16 0:55 NYPD
1 32309934 12/31/2015 11:59:44 PM 01-01-16 1:26 NYPD
2 32309159 12/31/2015 11:59:29 PM 01-01-16 4:51 NYPD
3 32305098 12/31/2015 11:57:46 PM 01-01-16 7:43 NYPD
4 32306529 12/31/2015 11:56:58 PM 01-01-16 3:24 NYPD
... ... ... ... ...
300693 30281872 03/29/2015 12:33:41 AM NaN NYPD
300694 30281230 03/29/2015 12:33:28 AM 03/29/2015 02:33:59 AM NYPD
300695 30283424 03/29/2015 12:33:03 AM 03/29/2015 03:40:20 AM NYPD
300696 30280004 03/29/2015 12:33:02 AM 03/29/2015 04:38:35 AM NYPD
300697 30281825 03/29/2015 12:33:01 AM 03/29/2015 04:41:50 AM NYPD

Agency Name Complaint Type \


0 New York City Police Department Noise - Street/Sidewalk
1 New York City Police Department Blocked Driveway
2 New York City Police Department Blocked Driveway
3 New York City Police Department Illegal Parking
4 New York City Police Department Illegal Parking
... ... ...
300693 New York City Police Department Noise - Commercial
300694 New York City Police Department Blocked Driveway
300695 New York City Police Department Noise - Commercial
300696 New York City Police Department Noise - Commercial
300697 New York City Police Department Noise - Commercial

Descriptor Location Type Incident Zip \


0 Loud Music/Party Street/Sidewalk 10034.0
1 No Access Street/Sidewalk 11105.0
2 No Access Street/Sidewalk 10458.0
3 Commercial Overnight Parking Street/Sidewalk 10461.0
4 Blocked Sidewalk Street/Sidewalk 11373.0
... ... ... ...
300693 Loud Music/Party Club/Bar/Restaurant NaN
300694 Partial Access Street/Sidewalk 11418.0
300695 Loud Music/Party Club/Bar/Restaurant 11206.0
300696 Loud Music/Party Club/Bar/Restaurant 10461.0
300697 Loud Music/Party Store/Commercial 10036.0

Incident Address ... School Not Found Bridge Highway Name \


0 71 VERMILYEA AVENUE ... N NaN
1 27-07 23 AVENUE ... N NaN
2 2897 VALENTINE AVENUE ... N NaN
3 2940 BAISLEY AVENUE ... N NaN
4 87-14 57 ROAD ... N NaN
... ... ... ... ...
300693 CRESCENT AVENUE ... N NaN
300694 100-17 87 AVENUE ... N NaN
300695 162 THROOP AVENUE ... N NaN
300696 3151 EAST TREMONT AVENUE ... N NaN
300697 251 WEST 48 STREET ... N NaN

Bridge Highway Direction Road Ramp Bridge Highway Segment \


0 NaN NaN NaN
1 NaN NaN NaN
2 NaN NaN NaN
3 NaN NaN NaN
4 NaN NaN NaN
... ... ... ...
300693 NaN NaN NaN
300694 NaN NaN NaN
300695 NaN NaN NaN
300696 NaN NaN NaN
300697 NaN NaN NaN

Ferry Direction Ferry Terminal Name Latitude Longitude \


0 NaN NaN 40.865682 -73.923501
1 NaN NaN 40.775945 -73.915094
1 NaN NaN 40.775945 -73.915094
2 NaN NaN 40.870325 -73.888525
3 NaN NaN 40.835994 -73.828379
4 NaN NaN 40.733060 -73.874170
... ... ... ... ...
300693 NaN NaN NaN NaN
300694 NaN NaN 40.694077 -73.846087
300695 NaN NaN 40.699590 -73.944234
300696 NaN NaN 40.837708 -73.834587
300697 NaN NaN 40.760583 -73.985922

Location
0 (40.86568153633767, -73.92350095571744)
1 (40.775945312321085, -73.91509393898605)
2 (40.870324522111424, -73.88852464418646)
3 (40.83599404683083, -73.82837939584206)
4 (40.733059618956815, -73.87416975810375)
... ...
300693 NaN
300694 (40.69407728322387, -73.8460866160573)
300695 (40.69959035300927, -73.94423377144169)
300696 (40.8377075854206, -73.83458731019586)
300697 (40.76058322950115, -73.98592204392392)

[300698 rows x 48 columns]>

In [18]:
#Display the complaint type and city together
serv_nyc1.loc[:,['Complaint Type','City']]
Out[18]:

Complaint Type City

Noise -
0 NEW YORK
Street/Sidewalk

1 Blocked Driveway ASTORIA

2 Blocked Driveway BRONX

3 Illegal Parking BRONX

4 Illegal Parking ELMHURST

... ... ...

300693 Noise - Commercial NaN

300694 Blocked Driveway RICHMOND HILL

300695 Noise - Commercial BROOKLYN

300696 Noise - Commercial BRONX

300697 Noise - Commercial NEW YORK

300698 rows × 2 columns

In [19]:
#Find major complaint types
major=serv_nyc1.loc[:,"Complaint Type"]
major
Out[19]:
0 Noise - Street/Sidewalk
1 Blocked Driveway
2 Blocked Driveway
3 Illegal Parking
4 Illegal Parking
...
300693 Noise - Commercial
300694 Blocked Driveway
300695 Noise - Commercial
300695 Noise - Commercial
300696 Noise - Commercial
300697 Noise - Commercial
Name: Complaint Type, Length: 300698, dtype: object

In [20]:
major.unique()
Out[20]:
array(['Noise - Street/Sidewalk', 'Blocked Driveway', 'Illegal Parking',
'Derelict Vehicle', 'Noise - Commercial',
'Noise - House of Worship', 'Posting Advertisement',
'Noise - Vehicle', 'Animal Abuse', 'Vending', 'Traffic',
'Drinking', 'Bike/Roller/Skate Chronic', 'Panhandling',
'Noise - Park', 'Homeless Encampment', 'Urinating in Public',
'Graffiti', 'Disorderly Youth', 'Illegal Fireworks',
'Ferry Complaint', 'Agency Issues', 'Squeegee', 'Animal in a Park'],
dtype=object)

In [21]:
major.nunique()
Out[21]:
24

In [22]:
#major complaints are Blocked Driveway
top=major.value_counts()
top
Out[22]:
Blocked Driveway 77044
Illegal Parking 75361
Noise - Street/Sidewalk 48612
Noise - Commercial 35577
Derelict Vehicle 17718
Noise - Vehicle 17083
Animal Abuse 7778
Traffic 4498
Homeless Encampment 4416
Noise - Park 4042
Vending 3802
Drinking 1280
Noise - House of Worship 931
Posting Advertisement 650
Urinating in Public 592
Bike/Roller/Skate Chronic 427
Panhandling 307
Disorderly Youth 286
Illegal Fireworks 168
Graffiti 113
Agency Issues 6
Squeegee 4
Ferry Complaint 2
Animal in a Park 1
Name: Complaint Type, dtype: int64

In [23]:
# Find the top 10 complaint types
top.head(10)
Out[23]:
Blocked Driveway 77044
Illegal Parking 75361
Noise - Street/Sidewalk 48612
Noise - Commercial 35577
Noise - Commercial 35577
Derelict Vehicle 17718
Noise - Vehicle 17083
Animal Abuse 7778
Traffic 4498
Homeless Encampment 4416
Noise - Park 4042
Name: Complaint Type, dtype: int64

In [25]:
# Plot a bar graph of count vs. complaint types

In [26]:
major.value_counts().plot(kind='bar',title='count vs. complaint types')
Out[26]:
<matplotlib.axes._subplots.AxesSubplot at 0x265821e39d0>

In [27]:
#Visualize the complaint types
top.plot(kind='hist',title='Visualize the complaint types')
Out[27]:
<matplotlib.axes._subplots.AxesSubplot at 0x26582960d30>

In [28]:
#Display the major complaint types and their count
top.head(10).plot(kind='bar',title='The major complaint types and their count')
Out[28]:
<matplotlib.axes._subplots.AxesSubplot at 0x26582a3eb20>

In [ ]:

You might also like