Evaluate the FDNY Dataset

249 阅读4分钟

Evaluate the FDNY Dataset

Happy coding!


1: View and import the dataset

#Import the required libraries
import pandas as pd
#Import the Fire Department of New York City (FDNY) file
ds = pd.read_csv('C:\\Users\\kevin.zhang\\Lesson 7 -2\\FDNY\\FDNY.csv')

2: Analyze the dataset

#View the content of the data
ds.describe
<bound method NDFrame.describe of                                           FacilityName  \
0                                         FacilityName   
1                                   Engine 4/Ladder 15   
2                                  Engine 10/Ladder 10   
3                                             Engine 6   
4    Engine 7/Ladder 1/Battalion 1/Manhattan Boroug...   
..                                                 ...   
214                  Engine 162/Ladder 82/Battalion 23   
215                               Engine 167/Ladder 87   
216                               Engine 164/Ladder 84   
217                          Engine 168/EMS Station 23   
218                               Engine 151/Ladder 76   

              FacilityAddress        Borough  
0             FacilityAddress        Borough  
1             42 South Street      Manhattan  
2          124 Liberty Street      Manhattan  
3           49 Beekman Street      Manhattan  
4        100-104 Duane Street      Manhattan  
..                        ...            ...  
214         256 Nelson Avenue  Staten Island  
215         345 Annadale Road  Staten Island  
216  1560 Drumgoole Road West  Staten Island  
217     1100 Rossville Avenue  Staten Island  
218           7219 Amboy Road  Staten Island  

[219 rows x 3 columns]>
#View the first five records
ds.head()
.dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; }
FacilityName FacilityAddress Borough
0 FacilityName FacilityAddress Borough
1 Engine 4/Ladder 15 42 South Street Manhattan
2 Engine 10/Ladder 10 124 Liberty Street Manhattan
3 Engine 6 49 Beekman Street Manhattan
4 Engine 7/Ladder 1/Battalion 1/Manhattan Boroug... 100-104 Duane Street Manhattan
#Skip the duplicate header row
ds_skip = pd.read_csv('C:\\Users\\kevin.zhang\\Lesson 7 -2\\FDNY\\FDNY.csv',skiprows=1)
#Verify if the dataset is fixed
ds_skip.head()
.dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; }
FacilityName FacilityAddress Borough
0 Engine 4/Ladder 15 42 South Street Manhattan
1 Engine 10/Ladder 10 124 Liberty Street Manhattan
2 Engine 6 49 Beekman Street Manhattan
3 Engine 7/Ladder 1/Battalion 1/Manhattan Boroug... 100-104 Duane Street Manhattan
4 Ladder 8 14 North Moore Street Manhattan
#View the data statistics (Hint: use describe() method)
ds_skip.describe()
.dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; }
FacilityName FacilityAddress Borough
count 218 218 218
unique 218 218 5
top Engine 4/Ladder 15 42 South Street Brooklyn
freq 1 1 66
#View the attributes of the dataset (Hint: view the column names)
ds_skip.columns
Index(['FacilityName', 'FacilityAddress', 'Borough'], dtype='object')
#View the index of the dataset
ds_skip.index
RangeIndex(start=0, stop=218, step=1)

3: Find the total number of fire department facilities in New York city

#Count number of records for each attribute
ds_skip.count()
FacilityName       218
FacilityAddress    218
Borough            218
dtype: int64
#view the datatypes of all three attributes
ds_skip.dtypes
FacilityName       object
FacilityAddress    object
Borough            object
dtype: object

4: Find the total number of fire department facilities in each borough

#Select FDNY information boroughwise
gb_ds = ds_skip.groupby('Borough')
#View FDNY informationn for each borough
gb_ds.size()
Borough
Bronx            34
Brooklyn         66
Manhattan        48
Queens           50
Staten Island    20
dtype: int64

5: Find the total number of fire department facilities in Manhattan

#Select FDNY information for Manhattan
ds_man = gb_ds.get_group('Manhattan')
#View FDNY information for Manhattan
ds_man
.dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; }
FacilityName FacilityAddress Borough
0 Engine 4/Ladder 15 42 South Street Manhattan
1 Engine 10/Ladder 10 124 Liberty Street Manhattan
2 Engine 6 49 Beekman Street Manhattan
3 Engine 7/Ladder 1/Battalion 1/Manhattan Boroug... 100-104 Duane Street Manhattan
4 Ladder 8 14 North Moore Street Manhattan
5 Engine 9/Ladder 6 75 Canal Street Manhattan
6 Engine 15/Ladder 18/Battalion 4 25 Pitt Street Manhattan
7 Engine 28/Ladder 11 222 East 2nd Street Manhattan
8 Engine 5 340 East 14th Street Manhattan
9 Engine 55 363 Broome Street Manhattan
10 Ladder 20/Division 1 253 Lafayette Street Manhattan
11 Engine 24/Ladder 5/Battalion 2 227-29 6th Avenue Manhattan
12 Engine 33/Ladder 9 42 Great Jones Street Manhattan
13 Ladder 3/Battalion 6 108 East 13th Street Manhattan
14 Squad 18 132 West 10th Street Manhattan
15 Engine 34/Ladder 21 440 West 38th Street Manhattan
16 Engine 26 220 West 37th Street Manhattan
17 Engine 3/Ladder 12/Battalion 7 150 West 19th Street Manhattan
18 Engine 1/Ladder 24 142-46 West 31st Street Manhattan
19 Engine 14 14 East 18th Street Manhattan
20 Engine 16 / Ladder 7 234 East 29th Street Manhattan
21 Engine 21 238 East 40th Street Manhattan
22 Engine 54/Ladder 4/Battalion 9 782 8th Avenue Manhattan
23 Engine 23 215 West 58th Street Manhattan
24 Rescue 1 530 West 43rd Street Manhattan
25 Engine 40/Ladder 35 131 Amsterdam Avenue Manhattan
26 Ladder 25/District Office 4/Division 3 205-207 West 77th Street Manhattan
27 Engine 74 120 West 83rd Street Manhattan
28 Engine 65 33 West 43rd Street Manhattan
29 Engine 8 / Ladder 2 / Battalion 8 167 East 51st Street Manhattan
30 Engine 39/Ladder 16 157-59 East 67th Street Manhattan
31 Engine 44 221 East 75th Street Manhattan
32 Engine 22/Ladder 13/Battalion 10 159 East 85th Street Manhattan
33 Engine 58/Ladder 26 1367 5th Avenue Manhattan
34 Engine 53/Ladder 43 1836-46 3rd Avenue Manhattan
35 Engine 91 242 East 111th Street Manhattan
36 Engine 35/Ladder 14 2282 3rd Avenue Manhattan
37 Engine 76/Ladder 22/Battalion 11 145-51 West 100th Street Manhattan
38 Engine 47 502 West 113th Street Manhattan
39 Engine 59/Ladder 30 111 West 133rd Street Manhattan
40 Engine 37/Ladder 40 415 West 125th Street Manhattan
41 Engine 69/Ladder 28/Battalion 16 248 West 143rd Street Manhattan
42 Engine 80/Ladder 23 503 West 139th Street Manhattan
43 Engine 84/Ladder 34 513 West 161st Street Manhattan
44 Engine 67 518 West 170th Street Manhattan
45 Engine 93/Ladder 45/Battalion 13 515 West 181st Street Manhattan
46 Engine 95/Ladder 36 29 Vermilyea Avenue Manhattan
47 Marine 1 Little West 12th Street/Hudson River Manhattan