Table of Contents

  • 1  Folium Map of Data Points

Folium Map of Data Points¶

In [1]:
# import libraries
import folium
from folium import plugins
import ipywidgets
import geocoder
import geopy
import numpy as np 
import pandas as pd 
from vega_datasets import data as vds 
In [2]:
# initiate map
map1 = folium.Map(location=[41.8781, -87.6298], zoom_start=10, width=500, height=300, control_scale=True)
In [3]:
# load airports
airports = vds.airports()
In [4]:
# load zipcodes, narrow to IL
zipcodes = vds.zipcodes()
zipcodes[zipcodes['state']== 'IL']
Out[4]:
zip_code latitude longitude city state county
25988 60001 42.324761 -88.452481 Alden IL Mchenry
25989 60002 42.451419 -88.075733 Antioch IL Lake
25990 60004 42.085626 -87.998220 Arlington Heights IL Cook
25991 60005 42.060928 -87.883073 Arlington Heights IL Cook
25992 60006 41.811929 -87.687320 Arlington Heights IL Cook
... ... ... ... ... ... ...
27573 62995 37.424170 -88.898049 Vienna IL Johnson
27574 62996 37.164229 -89.170924 Villa Ridge IL Pulaski
27575 62997 37.984776 -89.589862 Willisville IL Perry
27576 62998 37.509618 -89.424913 Wolf Lake IL Union
27577 62999 37.899054 -89.052317 Zeigler IL Franklin

1590 rows × 6 columns

In [5]:
# columns of zipcode dataframe
zipcodes.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 42049 entries, 0 to 42048
Data columns (total 6 columns):
 #   Column     Non-Null Count  Dtype  
---  ------     --------------  -----  
 0   zip_code   42049 non-null  object 
 1   latitude   42049 non-null  float64
 2   longitude  42049 non-null  float64
 3   city       42049 non-null  object 
 4   state      42049 non-null  object 
 5   county     42049 non-null  object 
dtypes: float64(2), object(4)
memory usage: 1.9+ MB
In [6]:
# multiple markers using dictionary
markers_dict = {'The Loop' : [41.8786, -87.6251],
                'River North' : [41.8924, -87.6341],
                'Streeterville' : [41.8927, -87.6200],
                'West Loop': [41.8854, -87.6627],
                "O'Hare" : [41.9773, -87.8369]}

# create map
map_cities = folium.Map(location=[41.9, -87.6], zoom_start=12)

# plot locations
for i in markers_dict.items():
    folium.Marker(location=i[1], popup=i[0], icon=folium.Icon(color='green', icon='car', prefix='fa')
    ).add_to(map_cities)

# measure control
measure_control = plugins.MeasureControl(position='topleft', active_color='blue', completed_color='green', primary_length_unit='miles')

# add measure control to map
map_cities.add_child(measure_control)
# display map
map_cities
Out[6]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [7]:
# save maps
map_cities.save('/Users/XIX/Documents/coding/projects/Project 6 - Data Collection and Storage/Zuber-Web-Scrapping/figures/map_cities.html')
map_cities.save('/Users/XIX/Documents/coding/projects/Project 6 - Data Collection and Storage/Zuber-Web-Scrapping/figures/map_cities.jpg')
'the_loop' = [41.8786, -87.6251, 10727.47 / 100]¶
'river_north' = [41.8924, -87.6341,9523.67 / 100]¶
'streeterville' = [41.8927, -87.6200,6664.67 / 100]¶
'west_loop'= [41.8854, -87.6627, 5163.66 / 100]¶
"o'hare" = [41.9773, -87.8369, 2546.9 / 100]¶
In [8]:
# get location data from dataset
loop = [41.8786, -87.6251, 10727.47 * 1000]
river_north = [41.8924, -87.6341,9523.67 * 1000]
streeterville = [41.8927, -87.6200,6664.67 * 1000]
west_loop = [41.8854, -87.6627, 5163.66 * 1000]
ohare = [41.9773, -87.8369, 2546.9 * 1000]

# create list of cities
dropoff_cities = [loop, river_north, streeterville, west_loop, ohare]

map_heatmap = folium.Map([41.9, -87.6], tiles='CartoDB Positron', zoom_start=12)

plugins.HeatMap(dropoff_cities).add_to(map_heatmap)

map_heatmap
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook