In [1]:
import berrl as bl
import numpy as np
import pandas as pd
apikey='pk.eyJ1IjoibXVycGh5MjE0IiwiYSI6ImNpam5kb3puZzAwZ2l0aG01ZW1uMTRjbnoifQ.5Znb4MArp7v3Wwrn6WFE6A'
data=pd.read_csv('wv_traffic_fatals.csv')
#data=data[data.CNTYNAME=='Clay County']
a=bl.make_points(data,list=True)
bl.parselist(a,'fatals.geojson')
# returns url to be used in show() function
url=bl.loadparsehtml(['fatals.geojson'],apikey,frame=True)
bl.show(url)
Out[1]:
In [2]:
# getting only the fatalities on certain routes
roadways=bl.get_filetype('roadways','csv')
totaluniques=[]
count=0
filenames=[]
for row in roadways:
count+=1
temp=bl.map_table(row,6)
uniques=np.unique(temp['GEOHASH']).tolist()
totaluniques+=uniques
temp['color']='light green'
a=bl.make_line(temp,list=True)
bl.parselist(a,str(count)+'.geojson')
filenames.append(str(count)+'.geojson')
totaluniques=np.unique(totaluniques)
In [3]:
# mapping all traffic fatals in WV to a geohash
data=bl.map_table(data,6,list=True)
matched=[]
# getting matching uniques
for row in bl.df2list(data):
oldrow=row
for row in totaluniques:
if oldrow[-1]==row:
matched.append(row)
# getting point
for row in matched:
count+=1
temp=data[data.GEOHASH==row]
temp['color']='red'
a=bl.make_points(temp,list=True)
bl.parselist(a,str(count)+'.geojson')
filenames.append(str(count)+'.geojson')
newurl=bl.loadparsehtml(filenames,apikey,colorkey='color',frame=True)
In [4]:
bl.show(newurl)
Out[4]:
In [ ]: