5. pandas案例:2015到2017年25万条911的紧急电话的数据分析

2015到2017年25万条911的紧急电话的数据分析

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

统计出出这些数据中不同类型的紧急情况的次数

data=pd.read_csv("./911.csv")

data.head()
data.shape

(652692, 9)

class_list=data[“title”].unique()

len(class_list)

148

创建一个用于统计报警电话类型的0矩阵

genre=pd.DataFrame(np.zeros((652692,148),dtype=np.int32),columns=class_list)

genre.head()

.dataframe thead th {
text-align: left;
}

.dataframe tbody tr th {
vertical-align: top;
}


EMS: BACK PAINS/INJURY EMS: DIABETIC EMERGENCY Fire: GAS-ODOR/LEAK EMS: CARDIAC EMERGENCY EMS: DIZZINESS EMS: HEAD INJURY EMS: NAUSEA/VOMITING EMS: RESPIRATORY EMERGENCY EMS: SYNCOPAL EPISODE Traffic: VEHICLE ACCIDENT - … EMS: VEHICLE LEAKING FUEL Fire: POISONING EMS: POLICE INFORMATION Fire: FOOT PATROL Fire: DIZZINESS Fire: ROAD OBSTRUCTION Fire: HEMORRHAGING EMS: BARRICADED SUBJECT Fire: CVA/STROKE Fire: BARRICADED SUBJECT
0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0
5 rows × 148 columns

给0矩阵填入数字

for i in range(652691):
genre.loc[i,data[“title”][i]]=1

result=genre.sum(axis=0).sort_values(ascending=False)

result[0:10][0:10]

Traffic: VEHICLE ACCIDENT - 146591
Traffic: DISABLED VEHICLE - 47210
Fire: FIRE ALARM 37643
EMS: FALL VICTIM 33986
EMS: RESPIRATORY EMERGENCY 33737
EMS: CARDIAC EMERGENCY 31813
EMS: VEHICLE ACCIDENT 25172
Traffic: ROAD OBSTRUCTION - 22747
EMS: SUBJECT IN PAIN 19304
EMS: HEAD INJURY 17974
dtype: int64

竟然有这么简单的功能可以直接显示结果。。

summary=data[“title”].value_counts()
summary.div(summary.sum())[0:10].plot(kind=“bar”)

<matplotlib.axes._subplots.AxesSubplot at 0x7f7371f32240>

统计出911数据中不同月份电话次数的变化情况 统计出不同月份不同类型紧急电话的次数的变化情况

data.head(2)

.dataframe thead th {
text-align: left;
}

.dataframe tbody tr th {
vertical-align: top;
}


lat lng desc zip title timeStamp twp addr e
0 40.297876 -75.581294 REINDEER CT & DEAD END; NEW HANOVER; Station … 19525.0 EMS: BACK PAINS/INJURY 2015-12-10 17:10:52 NEW HANOVER REINDEER CT & DEAD END 1
1 40.258061 -75.264680 BRIAR PATH & WHITEMARSH LN; HATFIELD TOWNSHIP… 19446.0 EMS: DIABETIC EMERGENCY 2015-12-10 17:29:21 HATFIELD TOWNSHIP BRIAR PATH & WHITEMARSH LN 1

data1=data

data1=data1.set_index(“timeStamp”)

data1

.dataframe thead th {
text-align: left;
}

.dataframe tbody tr th {
vertical-align: top;
}


lat lng desc zip title twp addr e month
timeStamp
2015-12-10 17:10:52 40.297876 -75.581294 REINDEER CT & DEAD END; NEW HANOVER; Station … 19525.0 EMS: BACK PAINS/INJURY NEW HANOVER REINDEER CT & DEAD END 1 1
2015-12-10 17:29:21 40.258061 -75.264680 BRIAR PATH & WHITEMARSH LN; HATFIELD TOWNSHIP… 19446.0 EMS: DIABETIC EMERGENCY HATFIELD TOWNSHIP BRIAR PATH & WHITEMARSH LN 1 1
2015-12-10 14:39:21 40.121182 -75.351975 HAWS AVE; NORRISTOWN; 2015-12-10 @ 14:39:21-St… 19401.0 Fire: GAS-ODOR/LEAK NORRISTOWN HAWS AVE 1 1
2015-12-10 16:47:36 40.116153 -75.343513 AIRY ST & SWEDE ST; NORRISTOWN; Station 308A;… 19401.0 EMS: CARDIAC EMERGENCY NORRISTOWN AIRY ST & SWEDE ST 1 1
2015-12-10 16:56:52 40.251492 -75.603350 CHERRYWOOD CT & DEAD END; LOWER POTTSGROVE; S… NaN EMS: DIZZINESS LOWER POTTSGROVE CHERRYWOOD CT & DEAD END 1 1
2015-12-10 15:39:04 40.253473 -75.283245 CANNON AVE & W 9TH ST; LANSDALE; Station 345;… 19446.0 EMS: HEAD INJURY LANSDALE CANNON AVE & W 9TH ST 1 1
2015-12-10 16:46:48 40.182111 -75.127795 LAUREL AVE & OAKDALE AVE; HORSHAM; Station 35… 19044.0 EMS: NAUSEA/VOMITING HORSHAM LAUREL AVE & OAKDALE AVE 1 1
2015-12-10 16:17:05 40.217286 -75.405182 COLLEGEVILLE RD & LYWISKI RD; SKIPPACK; Stati… 19426.0 EMS: RESPIRATORY EMERGENCY SKIPPACK COLLEGEVILLE RD & LYWISKI RD 1 1
2015-12-10 16:51:42 40.289027 -75.399590 MAIN ST & OLD SUMNEYTOWN PIKE; LOWER SALFORD;… 19438.0 EMS: SYNCOPAL EPISODE LOWER SALFORD MAIN ST & OLD SUMNEYTOWN PIKE 1 1
2015-12-10 17:35:41 40.102398 -75.291458 BLUEROUTE & RAMP I476 NB TO CHEMICAL RD; PLYM… 19462.0 Traffic: VEHICLE ACCIDENT - PLYMOUTH BLUEROUTE & RAMP I476 NB TO CHEMICAL RD 1 1
2015-12-10 17:33:50 40.231990 -75.251891 RT202 PKWY & KNAPP RD; MONTGOMERY; 2015-12-10 … NaN Traffic: VEHICLE ACCIDENT - MONTGOMERY RT202 PKWY & KNAPP RD 1 1
2015-12-10 16:32:10 40.084161 -75.308386 BROOK RD & COLWELL LN; PLYMOUTH; 2015-12-10 @ … 19428.0 Traffic: VEHICLE ACCIDENT - PLYMOUTH BROOK RD & COLWELL LN 1 1
2015-12-10 17:15:49 40.174131 -75.098491 BYBERRY AVE & S WARMINSTER RD; UPPER MORELAND;… 19040.0 Traffic: VEHICLE ACCIDENT - UPPER MORELAND BYBERRY AVE & S WARMINSTER RD 1 1
2015-12-10 17:12:47 40.062974 -75.135914 OLD YORK RD & VALLEY RD; CHELTENHAM; 2015-12-1… 19027.0 Traffic: VEHICLE ACCIDENT - CHELTENHAM OLD YORK RD & VALLEY RD 1 1
2015-12-10 17:09:49 40.097222 -75.376195 SCHUYLKILL EXPY & CROTON RD UNDERPASS; UPPER M… NaN Traffic: VEHICLE ACCIDENT - UPPER MERION SCHUYLKILL EXPY & CROTON RD UNDERPASS 1 1
2015-12-10 17:31:00 40.223778 -75.235399 STUMP RD & WITCHWOOD DR; MONTGOMERY; 2015-12-1… 18936.0 Traffic: VEHICLE ACCIDENT - MONTGOMERY STUMP RD & WITCHWOOD DR 1 1
2015-12-10 17:42:44 40.243258 -75.286552 SUSQUEHANNA AVE & W MAIN ST; LANSDALE; Statio… 19446.0 EMS: RESPIRATORY EMERGENCY LANSDALE SUSQUEHANNA AVE & W MAIN ST 1 1
2015-12-10 17:41:54 40.312181 -75.574260 CHARLOTTE ST & MILES RD; NEW HANOVER; Station… 19525.0 EMS: DIZZINESS NEW HANOVER CHARLOTTE ST & MILES RD 1 1
2015-12-10 17:43:29 40.114239 -75.338508 PENN ST & ARCH ST; NORRISTOWN; Station 308A; … 19401.0 EMS: VEHICLE ACCIDENT NORRISTOWN PENN ST & ARCH ST 1 1
2015-12-10 17:45:23 40.209337 -75.135266 COUNTY LINE RD & WILLOW DR; HORSHAM; 2015-12-1… 18974.0 Traffic: DISABLED VEHICLE - HORSHAM COUNTY LINE RD & WILLOW DR 1 1
2015-12-10 17:43:45 40.114239 -75.338508 PENN ST & ARCH ST; NORRISTOWN; 2015-12-10 @ 17… 19401.0 Traffic: VEHICLE ACCIDENT - NORRISTOWN PENN ST & ARCH ST 1 1
2015-12-10 17:53:22 40.117948 -75.209848 CHURCH RD & REDCOAT DR; WHITEMARSH; 2015-12-10… 19031.0 Traffic: DISABLED VEHICLE - WHITEMARSH CHURCH RD & REDCOAT DR 1 1
2015-12-10 17:59:24 40.199006 -75.300058 LILAC CT & PRIMROSE DR; UPPER GWYNEDD; 2015-12… 19446.0 Fire: APPLIANCE FIRE UPPER GWYNEDD LILAC CT & PRIMROSE DR 1 1
2015-12-10 18:00:38 40.143326 -75.422819 RT422 & PAWLINGS RD OVERPASS; LOWER PROVIDENC… NaN Traffic: DISABLED VEHICLE - LOWER PROVIDENCE RT422 & PAWLINGS RD OVERPASS 1 1
2015-12-10 17:58:22 40.153268 -75.189558 SUMMIT AVE & RT309 UNDERPASS; UPPER DUBLIN; 20… NaN Traffic: VEHICLE ACCIDENT - UPPER DUBLIN SUMMIT AVE & RT309 UNDERPASS 1 1
2015-12-10 18:02:02 40.133037 -75.408463 SHANNONDELL DR & SHANNONDELL BLVD; LOWER PROV… 19403.0 EMS: GENERAL WEAKNESS LOWER PROVIDENCE SHANNONDELL DR & SHANNONDELL BLVD 1 1
2015-12-10 18:02:38 40.155283 -75.264230 PENLLYN BLUE BELL PIKE & VILLAGE CIR; WHITPAI… 19422.0 EMS: HEAD INJURY WHITPAIN PENLLYN BLUE BELL PIKE & VILLAGE CIR 1 1
2015-12-10 18:05:19 40.028903 -75.351822 EDENTON PL & DURHAM DR; DELAWARE COUNTY; 2015-… 19085.0 Fire: CARBON MONOXIDE DETECTOR DELAWARE COUNTY EDENTON PL & DURHAM DR 1 1
2015-12-10 18:05:39 40.097222 -75.376195 SCHUYLKILL EXPY & WEADLEY RD OVERPASS; UPPER M… NaN Traffic: VEHICLE ACCIDENT - UPPER MERION SCHUYLKILL EXPY & WEADLEY RD OVERPASS 1 1
2015-12-10 18:10:40 40.209337 -75.135266 COUNTY LINE RD & WILLOW DR; HORSHAM; 2015-12-1… 18974.0 Traffic: DISABLED VEHICLE - HORSHAM COUNTY LINE RD & WILLOW DR 1 1
… … … … … … … … … …
2020-06-29 09:45:05 40.180105 -75.362530 TOWNSHIP LINE RD & VALLEY FORGE RD; WORCESTER;… 19403.0 Traffic: VEHICLE ACCIDENT - WORCESTER TOWNSHIP LINE RD & VALLEY FORGE RD 1 1
2020-06-29 09:44:23 40.215364 -75.332725 MORRIS RD & VALLEY VIEW WAY; TOWAMENCIN; 2020-… 19446.0 Traffic: VEHICLE ACCIDENT - TOWAMENCIN MORRIS RD & VALLEY VIEW WAY 1 1
2020-06-29 09:43:19 40.316626 -75.322707 N 4TH ST & RIDGE AVE; SOUDERTON; 2020-06-29 @ … 18964.0 Traffic: VEHICLE ACCIDENT - SOUDERTON N 4TH ST & RIDGE AVE 1 1
2020-06-29 09:46:34 40.169292 -75.241381 CHESHIRE DR & STAFFORD DR; LOWER GWYNEDD; Sta… 19422.0 EMS: FALL VICTIM LOWER GWYNEDD CHESHIRE DR & STAFFORD DR 1 1
2020-06-29 09:47:08 40.100423 -75.207064 RT309 EXPY & RAMP PAPER MILL RD TO RT309 NB; S… NaN Traffic: DISABLED VEHICLE - SPRINGFIELD RT309 EXPY & RAMP PAPER MILL RD TO RT309 NB 1 1
2020-06-29 09:52:57 40.178442 -75.128506 RIDGEVIEW DR & DEAD END; HORSHAM; 2020-06-29 @… NaN Fire: FIRE ALARM HORSHAM RIDGEVIEW DR & DEAD END 1 1
2020-06-29 09:52:57 40.230106 -75.297077 ALLENTOWN RD; UPPER GWYNEDD; 2020-06-29 @ 09:5… 19446.0 Fire: FIRE ALARM UPPER GWYNEDD ALLENTOWN RD 1 1
2020-06-29 10:03:42 40.114404 -75.121760 OLD YORK RD & SUSQUEHANNA RD; ABINGTON; 2020-0… 19001.0 Traffic: VEHICLE ACCIDENT - ABINGTON OLD YORK RD & SUSQUEHANNA RD 1 1
2020-06-29 10:15:33 40.235495 -75.308292 SNYDER RD & VALLEY FORGE RD; TOWAMENCIN; Stat… 19446.0 EMS: UNRESPONSIVE SUBJECT TOWAMENCIN SNYDER RD & VALLEY FORGE RD 1 1
2020-06-29 10:13:52 40.257428 -75.214149 DOYLESTOWN PIKE & COUNTY LINE RD; MONTGOMERY; … NaN Traffic: VEHICLE ACCIDENT - MONTGOMERY DOYLESTOWN PIKE & COUNTY LINE RD 1 1
2020-06-29 10:24:32 40.123917 -75.117162 OLD YORK RD & LONDON RD; ABINGTON; 2020-06-29 … 19001.0 Fire: FIRE ALARM ABINGTON OLD YORK RD & LONDON RD 1 1
2020-06-29 10:21:55 40.019219 -75.275368 GYPSY LN & ADRIENNE LN; LOWER MERION; Station… 19096.0 EMS: CVA/STROKE LOWER MERION GYPSY LN & ADRIENNE LN 1 1
2020-06-29 10:28:24 40.129671 -75.373143 MAIN ST & S WAKEFIELD RD; WEST NORRITON; Stat… 19403.0 EMS: GENERAL WEAKNESS WEST NORRITON MAIN ST & S WAKEFIELD RD 1 1
2020-06-29 10:29:19 40.348473 -75.631154 LANDIS LN & W READING RD; BERKS COUNTY; Stati… 19512.0 EMS: MEDICAL ALERT ALARM BERKS COUNTY LANDIS LN & W READING RD 1 1
2020-06-29 10:37:30 40.153754 -75.121604 EASTON RD & LAWNTON RD; UPPER MORELAND; Stati… 19090.0 EMS: CARDIAC EMERGENCY UPPER MORELAND EASTON RD & LAWNTON RD 1 1
2020-06-29 10:43:58 40.001798 -75.302803 MORRIS RD & CRICKET AVE; DELAWARE COUNTY; Sta… 19003.0 EMS: MEDICAL ALERT ALARM DELAWARE COUNTY MORRIS RD & CRICKET AVE 1 1
2020-06-29 10:46:10 40.124635 -75.117238 OLD YORK RD & WHEATSHEAF LN; ABINGTON; 2020-06… 19001.0 Fire: FIRE ALARM ABINGTON OLD YORK RD & WHEATSHEAF LN 1 1
2020-06-29 10:49:06 40.156621 -75.411326 EAGLEVILLE RD & SUNDERLAND DR; LOWER PROVIDEN… 19403.0 EMS: CVA/STROKE LOWER PROVIDENCE EAGLEVILLE RD & SUNDERLAND DR 1 1
2020-06-29 11:00:17 40.267807 -75.294721 DOGWOOD LN & SCHWAB RD; HATFIELD TOWNSHIP; St… 19440.0 EMS: DIABETIC EMERGENCY HATFIELD TOWNSHIP DOGWOOD LN & SCHWAB RD 1 1
2020-06-29 10:57:56 40.131564 -75.251261 BUTLER PIKE & HAMPTON LN; WHITPAIN; 2020-06-29… 19422.0 Traffic: VEHICLE ACCIDENT - WHITPAIN BUTLER PIKE & HAMPTON LN 1 1
2020-06-29 11:01:23 40.225008 -75.326022 ANDERS RD & MEADOW GLEN DR; TOWAMENCIN; Stati… 19446.0 EMS: BACK PAINS/INJURY TOWAMENCIN ANDERS RD & MEADOW GLEN DR 1 1
2020-06-29 11:04:24 40.123761 -75.401557 GENERAL ARMISTEAD AVE & GENERAL WASHINGTON AVE… 19403.0 EMS: CARDIAC EMERGENCY WEST NORRITON GENERAL ARMISTEAD AVE & GENERAL WASHINGTON AVE 1 1
2020-06-29 11:03:54 40.167178 -75.132361 BLAIR MILL RD & CARRELL LN; UPPER MORELAND; S… 19090.0 EMS: CVA/STROKE UPPER MORELAND BLAIR MILL RD & CARRELL LN 1 1
2020-06-29 11:12:11 40.005431 -75.261123 FORREST AVE & HAVERFORD AVE; NARBERTH; 2020-06… 19072.0 Traffic: ROAD OBSTRUCTION - NARBERTH FORREST AVE & HAVERFORD AVE 1 1
2020-06-29 11:17:43 40.078276 -75.249852 RIDGE PIKE & BARREN HILL RD; WHITEMARSH; Stat… 19444.0 EMS: ALTERED MENTAL STATUS WHITEMARSH RIDGE PIKE & BARREN HILL RD 1 1
2020-06-29 11:20:11 40.116526 -75.340552 DEKALB ST & E MARSHALL ST; NORRISTOWN; Statio… 19401.0 EMS: SEIZURES NORRISTOWN DEKALB ST & E MARSHALL ST 1 1
2020-06-29 11:16:38 40.081618 -75.405643 BRYCE LN & E SWEDESFORD RD; UPPER MERION; Sta… 19406.0 EMS: POISONING UPPER MERION BRYCE LN & E SWEDESFORD RD 1 1
2020-06-29 11:17:27 40.172526 -75.284653 DEKALB PIKE & BLUE BELL SPRINGS DR; WHITPAIN; … 19422.0 Traffic: VEHICLE ACCIDENT - WHITPAIN DEKALB PIKE & BLUE BELL SPRINGS DR 1 1
2020-06-29 11:23:32 40.376450 -75.481847 5TH ST & BITTING ALY; RED HILL; Station 369; … 18076.0 EMS: BACK PAINS/INJURY RED HILL 5TH ST & BITTING ALY 1 1
2020-06-29 11:27:40 40.176853 -75.080834 COUNTY LINE RD & CENTENNIAL RD; UPPER MORELAN… 19040.0 EMS: FALL VICTIM UPPER MORELAND COUNTY LINE RD & CENTENNIAL RD 1 1
652692 rows × 9 columns

date=pd.to_datetime(data1.index).month

data1[“month”]=date

data1.groupby([“month”])[“e”].count().sort_values(ascending=False).plot(kind=“bar”)

<matplotlib.axes._subplots.AxesSubplot at 0x7f734f77d2b0>

data1.groupby([“month”,“title”])[“e”].count()

month title
1 EMS: ABDOMINAL PAINS 873
EMS: ALLERGIC REACTION 209
EMS: ALTERED MENTAL STATUS 968
EMS: AMPUTATION 8
EMS: ANIMAL BITE 30
EMS: APPLIANCE FIRE 4
EMS: ASSAULT VICTIM 333
EMS: BACK PAINS/INJURY 469
EMS: BARRICADED SUBJECT 1
EMS: BUILDING FIRE 144
EMS: BURN VICTIM 25
EMS: CARBON MONOXIDE DETECTOR 59
EMS: CARDIAC ARREST 421
EMS: CARDIAC EMERGENCY 3056
EMS: CHOKING 104
EMS: CVA/STROKE 782
EMS: DEHYDRATION 143
EMS: DIABETIC EMERGENCY 524
EMS: DIZZINESS 488
EMS: DROWNING 1
EMS: ELECTRICAL FIRE OUTSIDE 3
EMS: ELECTROCUTION 1
EMS: ELEVATOR EMERGENCY 1
EMS: EMS SPECIAL SERVICE 107
EMS: EYE INJURY 17
EMS: FALL VICTIM 3278
EMS: FEVER 366
EMS: FIRE ALARM 6
EMS: FIRE INVESTIGATION 10
EMS: FIRE SPECIAL SERVICE 49

12 Fire: FIRE SPECIAL SERVICE 335
Fire: GAS-ODOR/LEAK 675
Fire: HAZARDOUS MATERIALS INCIDENT 3
Fire: HEMORRHAGING 1
Fire: MEDICAL ALERT ALARM 1
Fire: OVERDOSE 2
Fire: PUMP DETAIL 2
Fire: RESCUE - ELEVATOR 80
Fire: RESCUE - GENERAL 26
Fire: RESCUE - TECHNICAL 1
Fire: RESCUE - WATER 5
Fire: S/B AT HELICOPTER LANDING 50
Fire: SYNCOPAL EPISODE 1
Fire: TRAIN CRASH 3
Fire: TRANSFERRED CALL 8
Fire: TRASH/DUMPSTER FIRE 72
Fire: UNKNOWN MEDICAL EMERGENCY 1
Fire: UNKNOWN TYPE FIRE 113
Fire: UNRESPONSIVE SUBJECT 1
Fire: VEHICLE ACCIDENT 1018
Fire: VEHICLE FIRE 243
Fire: VEHICLE LEAKING FUEL 18
Fire: WOODS/FIELD FIRE 110
Traffic: DEBRIS/FLUIDS ON HIGHWAY - 15
Traffic: DISABLED VEHICLE - 4162
Traffic: HAZARDOUS ROAD CONDITIONS - 562
Traffic: ROAD OBSTRUCTION - 1325
Traffic: VEHICLE ACCIDENT - 14531
Traffic: VEHICLE FIRE - 251
Traffic: VEHICLE LEAKING FUEL - 19
Name: e, Length: 1279, dtype: int64

展开阅读全文
©️2020 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值