Data Source: https://www.kaggle.com/worldbank/world-development-indicators
Folder: 'world-development-indicators'
In [1]:
import folium
import pandas as pd
source: https://github.com/python-visualization/folium/blob/master/examples/data/world-countries.json
In [16]:
country_geo = r'/Users/Harish/Documents/HK_Work/Python/world-development-indicators/world-countries.json'
In [17]:
# Read in the World Development Indicators Database
data = pd.read_csv(r'/Users/Harish/Documents/HK_Work/Python/world-development-indicators/Indicators.csv')
data.shape
Out[17]:
In [18]:
data.head()
Out[18]:
Pull out CO2 emisions for every country in 2011
In [19]:
# select CO2 emissions for all countries in 2011
hist_indicator = 'CO2 emissions \(metric'
hist_year = 2011
mask1 = data['IndicatorName'].str.contains(hist_indicator)
mask2 = data['Year'].isin([hist_year])
# apply our mask
stage = data[mask1 & mask2]
stage.head()
Out[19]:
In [20]:
plot_data = stage[['CountryCode','Value']]
plot_data.head()
Out[20]:
In [21]:
# label for the legend
hist_indicator = stage.iloc[0]['IndicatorName']
In [22]:
# Setup a folium map at a high-level zoom @Alok - what is the 100,0, doesn't seem like lat long
map = folium.Map(location=[100, 0], zoom_start=1.5)
In [23]:
# choropleth maps bind Pandas Data Frames and json geometries. This allows us to quickly visualize data combinations
map.choropleth(geo_data=country_geo, data=plot_data,
columns=['CountryCode', 'Value'],
key_on='feature.id',
fill_color='YlGnBu', fill_opacity=0.7, line_opacity=0.2,
legend_name=hist_indicator)
In [12]:
# Create Folium plot
map.save('plot_data.html')
In [13]:
# Import the Folium interactive html file
from IPython.display import HTML
HTML('<iframe src=plot_data.html width=700 height=450></iframe>')
Out[13]:
More Folium Examples can be found at:
https://folium.readthedocs.io/en/latest/quickstart.html#getting-started
Documentation at:
https://media.readthedocs.org/pdf/folium/latest/folium.pdf
In [ ]: