Showing Berrl Implementation in Jupyter


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)


GeoJSON file written to location: fatals.geojson
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)


GeoJSON file written to location: 1.geojson
GeoJSON file written to location: 2.geojson
GeoJSON file written to location: 3.geojson
GeoJSON file written to location: 4.geojson
GeoJSON file written to location: 5.geojson
GeoJSON file written to location: 6.geojson
GeoJSON file written to location: 7.geojson
GeoJSON file written to location: 8.geojson
GeoJSON file written to location: 9.geojson
GeoJSON file written to location: 10.geojson
GeoJSON file written to location: 11.geojson
GeoJSON file written to location: 12.geojson
GeoJSON file written to location: 13.geojson
GeoJSON file written to location: 14.geojson
GeoJSON file written to location: 15.geojson
GeoJSON file written to location: 16.geojson
GeoJSON file written to location: 17.geojson
GeoJSON file written to location: 18.geojson
GeoJSON file written to location: 19.geojson
GeoJSON file written to location: 20.geojson
GeoJSON file written to location: 21.geojson
GeoJSON file written to location: 22.geojson
GeoJSON file written to location: 23.geojson
GeoJSON file written to location: 24.geojson
GeoJSON file written to location: 25.geojson
GeoJSON file written to location: 26.geojson
GeoJSON file written to location: 27.geojson
GeoJSON file written to location: 28.geojson
GeoJSON file written to location: 29.geojson
GeoJSON file written to location: 30.geojson
GeoJSON file written to location: 31.geojson
GeoJSON file written to location: 32.geojson
GeoJSON file written to location: 33.geojson

Mapping all fatalities and getting unique hashs for each


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)


GeoJSON file written to location: 34.geojson
GeoJSON file written to location: 35.geojson
GeoJSON file written to location: 36.geojson
GeoJSON file written to location: 37.geojson
GeoJSON file written to location: 38.geojson
GeoJSON file written to location: 39.geojson
GeoJSON file written to location: 40.geojson
GeoJSON file written to location: 41.geojson
GeoJSON file written to location: 42.geojson
GeoJSON file written to location: 43.geojson
GeoJSON file written to location: 44.geojson
/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:16: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

Showing the new url made with fatalities along certain routes


In [4]:
bl.show(newurl)


Out[4]:

In [ ]: