{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using geopandas and bokeh to create interactive world map with data" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [], "source": [ "import geopandas as gpd\n", "import pandas as pd\n", "import json\n", "from bokeh.io import output_notebook, show, output_file, curdoc\n", "from bokeh.plotting import figure\n", "from bokeh.models import GeoJSONDataSource, LinearColorMapper, ColorBar, Slider, HoverTool\n", "from bokeh.palettes import brewer\n", "from bokeh.layouts import widgetbox, row, column" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Data\n", "\n", "This notebook was created using this tutorial here:[A Complete Guide to an Interactive Geographical Map using Python.](https://towardsdatascience.com/a-complete-guide-to-an-interactive-geographical-map-using-python-f4c5197e23e0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introducing and Cleaning the Data" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | country | \n", "country_code | \n", "geometry | \n", "
|---|---|---|---|
| 0 | \n", "Fiji | \n", "FJI | \n", "MULTIPOLYGON (((180.00000 -16.06713, 180.00000... | \n", "
| 1 | \n", "United Republic of Tanzania | \n", "TZA | \n", "POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... | \n", "
| 2 | \n", "Western Sahara | \n", "SAH | \n", "POLYGON ((-8.66559 27.65643, -8.66512 27.58948... | \n", "
| 3 | \n", "Canada | \n", "CAN | \n", "MULTIPOLYGON (((-122.84000 49.00000, -122.9742... | \n", "
| 4 | \n", "United States of America | \n", "USA | \n", "MULTIPOLYGON (((-122.84000 49.00000, -120.0000... | \n", "
| \n", " | entity | \n", "code | \n", "year | \n", "percent_obesity | \n", "
|---|---|---|---|---|
| 0 | \n", "Afghanistan | \n", "AFG | \n", "1975 | \n", "0.5 | \n", "
| 1 | \n", "Afghanistan | \n", "AFG | \n", "1976 | \n", "0.5 | \n", "
| 2 | \n", "Afghanistan | \n", "AFG | \n", "1977 | \n", "0.6 | \n", "
| 3 | \n", "Afghanistan | \n", "AFG | \n", "1978 | \n", "0.6 | \n", "
| 4 | \n", "Afghanistan | \n", "AFG | \n", "1979 | \n", "0.6 | \n", "
| \n", " | entity | \n", "code | \n", "year | \n", "percent_obesity | \n", "
|---|---|---|---|---|
| 42 | \n", "Africa | \n", "NaN | \n", "1975 | \n", "2.0 | \n", "
| 43 | \n", "Africa | \n", "NaN | \n", "1976 | \n", "2.1 | \n", "
| 44 | \n", "Africa | \n", "NaN | \n", "1977 | \n", "2.2 | \n", "
| 45 | \n", "Africa | \n", "NaN | \n", "1978 | \n", "2.3 | \n", "
| 46 | \n", "Africa | \n", "NaN | \n", "1979 | \n", "2.3 | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| 8185 | \n", "Western Pacific | \n", "NaN | \n", "2012 | \n", "5.2 | \n", "
| 8186 | \n", "Western Pacific | \n", "NaN | \n", "2013 | \n", "5.5 | \n", "
| 8187 | \n", "Western Pacific | \n", "NaN | \n", "2014 | \n", "5.8 | \n", "
| 8188 | \n", "Western Pacific | \n", "NaN | \n", "2015 | \n", "6.1 | \n", "
| 8189 | \n", "Western Pacific | \n", "NaN | \n", "2016 | \n", "6.4 | \n", "
336 rows × 4 columns
\n", "\\n\"+\n", " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"\\n\"+\n",
" \"\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"\\n\"+\n \"\\n\"+\n", " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"\\n\"+\n",
" \"\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"\\n\"+\n \"\\n\"+\n", " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"\\n\"+\n",
" \"\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"\\n\"+\n \"\\n\"+\n", " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"\\n\"+\n",
" \"\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"\\n\"+\n \"