# -*- coding: utf-8 -*-
import pandas as pd
import folium
trafficAccident=pd.read_csv("./도로교통공단_교통사고다발지역_20191010utf8.csv")
#trafficAccident=pd.read_csv("./경기도교통사고.csv")
#trafficAccident
map_osm = folium.Map(location=[37.4729081, 127.039306])
folium.Marker([37.4729081, 127.039306]).add_to(map_osm)
map_osm
def make_marker(map_osm, x, y):
for i in range(len(x)):
folium.Marker([y[i], x[i]]).add_to(map_osm)
colorIndex=''
def make_Cmarker(map_osm, x, y, death):
#print(type(death))
for i in range(len(x)):
if(death[i] >= 0 & death[i] < 1):
colorIndex='yellow'
if(death[i] >= 2):
colorIndex='red'
else:
coloeIndex='black'
folium.CircleMarker([y[i], x[i]], fill_color=colorIndex, fill_opacity=0.7 ).add_to(map_osm)
trafficAccident.head()
#print(type(trafficAccident))
make_Cmarker(map_osm,trafficAccident['경도'],trafficAccident['위도'],trafficAccident['사망자수'] )
map_osm
trafficAccident.head(10)
#print(type(trafficAccident['사망자수']))
#print(trafficAccident['사망자수'].shape)
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
from matplotlib import font_manager, rc
font_name = font_manager.FontProperties(fname="/usr/share/fonts/truetype/nanum/NanumGothic.ttf").get_name()
rc('font', family=font_name)
%matplotlib inline
import pandas as pd
import numpy as np
deathRateDF=pd.DataFrame(trafficAccident['사고유형구분'])
deathRateDF.loc[:,'사망자수']=trafficAccident['사망자수']
deathRateDF.loc[:,'발생건수']=trafficAccident['발생건수']
#deathRate=trafficAccident['사망자수'].divide(trafficAccident['발생건수'])
#deathRateDF.loc[:,'사망율']=deathRate
deathRateGrouped = deathRateDF.groupby('사고유형구분')
label=['무단횡단', '보행노인', '보행어린이', '스쿨존어린이', '자전거']
#index=np.arange(len(label))
print(deathRateGrouped.sum()['사망자수']/deathRateGrouped.sum()['발생건수'])
plt.title("발생건수 대 사망자수")
plt.bar(label,deathRateGrouped.sum()['발생건수'])
plt.bar(label,deathRateGrouped.sum()['사망자수'])
plt.legend(deathRateGrouped.sum())
plt.show()
plt.title("사망률")
plt.scatter(label,deathRateGrouped.sum()['사망자수']/deathRateGrouped.sum()['발생건수'])
plt.show()
#보행노인 사고 발생 위치
def make_CategoryMarker(map_osm, x, y, typeAccident, CmpString, colorIndex):
for i in range(len(x)):
if(typeAccident[i]==CmpString):
folium.CircleMarker([y[i], x[i]], fill_color=colorIndex, fill_opacity=0.7 ).add_to(map_osm)
map_osm2 = folium.Map(location=[37.4729081, 127.039306])
make_CategoryMarker(map_osm2,trafficAccident['경도'],trafficAccident['위도'],trafficAccident['사고유형구분'], '보행노인','yellow')
make_CategoryMarker(map_osm2,trafficAccident['경도'],trafficAccident['위도'],trafficAccident['사고유형구분'], '무단횡단', 'blue')
map_osm2