#!/usr/bin/env python # coding: utf-8 # In[ ]: #https://www.gov.uk/government/statistics/sub-national-electricity-and-gas-consumption-at-lsoa-msoa-and-igz-level-in-2015 # In[1]: import pandas as pd # In[ ]: gasurl='https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/585723/LSOA_domestic_gas_2015.xlsx' elecurl='https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/585872/LSOA_domestic_electricity_2015.xlsx' # In[2]: gas=pd.read_excel('data/LSOA_domestic_gas_2015.xlsx',sheetname=1,skiprows=1) gas.head() # In[3]: elec=pd.read_excel('data/LSOA_domestic_electricity_2015.xlsx',sheetname=1,skiprows=1) elec.head() # In[4]: iwLA='E06000046' def geoJlocal(code): return '{}.json'.format(code) geoJlocal(iwLA) # In[13]: import folium #color brewer palettes: ‘BuGn’, ‘BuPu’, ‘GnBu’, ‘OrRd’, ‘PuBu’, ‘PuBuGn’, ‘PuRd’, ‘RdPu’, ‘YlGn’, ‘YlGnBu’, ‘YlOrBr’, and ‘YlOrRd’. import fiona geojson_local='travel-times/E06000046.json' fi=fiona.open(geojson_local) centre_lat,centre_lon=((fi.bounds[0]+fi.bounds[2])/2,(fi.bounds[1]+fi.bounds[3])/2) # In[14]: elecmap = folium.Map([centre_lon,centre_lat], zoom_start=11) elecmap.choropleth( geo_path=geojson_local, data=elec[elec['Local Authority Code']=='E06000046'], columns=['Lower Layer Super Output Area (LSOA) Code', 'Total domestic electricity consumption (kWh)'], key_on='feature.properties.LSOA11CD', fill_color='PuBuGn', fill_opacity=1.0 ) # In[20]: gasmap = folium.Map([centre_lon,centre_lat], zoom_start=11) gasmap.choropleth( geo_path=geojson_local, data=gas[gas['Local Authority Code']=='E06000046'], columns=['Lower Layer Super Output Area (LSOA) Code', 'Consumption (kWh)'], key_on='feature.properties.LSOA11CD', fill_color='RdPu', fill_opacity=1.0 ) # In[16]: elecmap # In[21]: gasmap