Day 7: Green ¶
For today's theme, I've decided to do sustainability-themed map. Raleigh Open Data has a nice dataset contianing the location and useful attributes about sustainable projects in and around Raleigh . I really enjoyed using CARTOframes on Day 1 and have decided to use it as my final map medium. What follows is my workflow for access the data and creating a exploratory map for filtering the sustainable projects on various attributes.
Libraries ¶
I have to install two libraries that don't come with Colaboratory's Python 3 environment: geopandas and CARTOframes.
! pip install geopandas cartoframes==1.0b4
import geopandas as gpd
from cartoframes.viz import Map, Layer, Popup, Legend, Layout, basemaps
from cartoframes.viz.widgets import category_widget, formula_widget
from cartoframes.viz.helpers import color_category_layer
Data ¶
green_gdf = gpd.read_file('https://opendata.arcgis.com/datasets/009aa26c5f54427cabf4b8042186947a_0.geojson')
display(green_gdf.info(), green_gdf.head())
Layout(
[
Map(
Layer(
green_gdf,
style = '''
color: green
width: 8
strokeWidth: 1
strokeColor: white
'''
)
)
],
map_height = 600
)
The data is in pretty good shape and there don't appear to be any missing geometries. A little tidying couldn't hurt though!
fillna_cols = ['CERTIFICATION', 'TYPE', 'STATUS']
[green_gdf[c].fillna('Not Indicated', inplace = True) for c in fillna_cols]
green_gdf['CERTIFICATION'] = green_gdf.apply(lambda x: 'No Certification' if x['CERTIFICATION'] == ' ' else x['CERTIFICATION'], axis = 1)
green_gdf = green_gdf[['NAME', 'CATEGORY', 'LOCATION', 'OWNER', 'TYPE', 'STATUS', 'CERTIFICATION', 'SIZE_', 'OUTPUT', 'URL', 'geometry']]
green_gdf.head()
Raleigh Sustainability Projects Explorer ¶
Map(
Layer(
green_gdf,
'''
color: #4CAF50
width: 8
strokeWidth: 1
strokeColor: white
''',
popup = Popup({
'click': [{
'title': 'Certification',
'value': '$CERTIFICATION'
}, {
'title': 'Project Use Type',
'value': '$TYPE'
}, {
'title': 'Owner',
'value': '$OWNER'
}, {
'title': 'Site Address',
'value': '$LOCATION'
}, {
'title': 'Site',
'value':'$NAME'
}
],
'hover': [{
'title': 'Site',
'value':'$NAME'
}]
}),
widgets = [
category_widget(
'CATEGORY',
title = 'Category'
), category_widget(
'TYPE',
title = 'Project Use Type'
), category_widget(
'CERTIFICATION',
title = 'Certification'
), category_widget(
'STATUS',
title = 'Project Status'
)
]
)
)