data/notebooks/Lab/6_analysis_exploration.ipynb
{
"cells": [
{
"cell_type": "markdown",
"id": "eebbf7a1",
"metadata": {},
"source": [
"## Analysis exploration\n",
"\n",
"Now that we have explore in the previous notebooks the workflow for the four different indicators, we are going to produce mock data to star exploring graphs and visualizations. The workflow that we are going to use would be covered in the table of contents:\n",
"\n",
"## Table of Contents\n",
"- ### [Python libraries](#libraries)\n",
"- ### [1. Explore mock data](#importData)\n",
"- ### [2. Default crop and pasture data](#crop_data)\n",
"- ### [3. Generate risk map](#risk)\n",
" - #### [3.1 Unsustainable water use risk](#waterRisk)\n",
" - #### [3.2 Deforestation risk](#deforestationRisk)\n",
" - #### [3.3 Carbon emissions due to land use change risk](#carbonRisk)\n",
" - #### [3.4 Biodiverstity loss due to land use change risk](#biodiversityRisk)\n",
"- ### [4. Get metrics for user data](#metric)\n",
"- ### [5. Final notes](#finalNotes)"
]
},
{
"cell_type": "markdown",
"id": "c903129f",
"metadata": {},
"source": [
"<a id='libraries'></a>\n",
"## Python libraries"
]
},
{
"cell_type": "code",
"execution_count": 249,
"id": "c17c311e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <div class=\"bk-root\">\n",
" <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
" <span id=\"6947\">Loading BokehJS ...</span>\n",
" </div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function(root) {\n",
" function now() {\n",
" return new Date();\n",
" }\n",
"\n",
" var force = true;\n",
"\n",
" if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
" root._bokeh_onload_callbacks = [];\n",
" root._bokeh_is_loading = undefined;\n",
" }\n",
"\n",
" var JS_MIME_TYPE = 'application/javascript';\n",
" var HTML_MIME_TYPE = 'text/html';\n",
" var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
" var CLASS_NAME = 'output_bokeh rendered_html';\n",
"\n",
" /**\n",
" * Render data to the DOM node\n",
" */\n",
" function render(props, node) {\n",
" var script = document.createElement(\"script\");\n",
" node.appendChild(script);\n",
" }\n",
"\n",
" /**\n",
" * Handle when an output is cleared or removed\n",
" */\n",
" function handleClearOutput(event, handle) {\n",
" var cell = handle.cell;\n",
"\n",
" var id = cell.output_area._bokeh_element_id;\n",
" var server_id = cell.output_area._bokeh_server_id;\n",
" // Clean up Bokeh references\n",
" if (id != null && id in Bokeh.index) {\n",
" Bokeh.index[id].model.document.clear();\n",
" delete Bokeh.index[id];\n",
" }\n",
"\n",
" if (server_id !== undefined) {\n",
" // Clean up Bokeh references\n",
" var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
" cell.notebook.kernel.execute(cmd, {\n",
" iopub: {\n",
" output: function(msg) {\n",
" var id = msg.content.text.trim();\n",
" if (id in Bokeh.index) {\n",
" Bokeh.index[id].model.document.clear();\n",
" delete Bokeh.index[id];\n",
" }\n",
" }\n",
" }\n",
" });\n",
" // Destroy server and session\n",
" var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
" cell.notebook.kernel.execute(cmd);\n",
" }\n",
" }\n",
"\n",
" /**\n",
" * Handle when a new output is added\n",
" */\n",
" function handleAddOutput(event, handle) {\n",
" var output_area = handle.output_area;\n",
" var output = handle.output;\n",
"\n",
" // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
" if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
" return\n",
" }\n",
"\n",
" var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
"\n",
" if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
" toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
" // store reference to embed id on output_area\n",
" output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
" }\n",
" if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
" var bk_div = document.createElement(\"div\");\n",
" bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
" var script_attrs = bk_div.children[0].attributes;\n",
" for (var i = 0; i < script_attrs.length; i++) {\n",
" toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
" toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
" }\n",
" // store reference to server id on output_area\n",
" output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
" }\n",
" }\n",
"\n",
" function register_renderer(events, OutputArea) {\n",
"\n",
" function append_mime(data, metadata, element) {\n",
" // create a DOM node to render to\n",
" var toinsert = this.create_output_subarea(\n",
" metadata,\n",
" CLASS_NAME,\n",
" EXEC_MIME_TYPE\n",
" );\n",
" this.keyboard_manager.register_events(toinsert);\n",
" // Render to node\n",
" var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
" render(props, toinsert[toinsert.length - 1]);\n",
" element.append(toinsert);\n",
" return toinsert\n",
" }\n",
"\n",
" /* Handle when an output is cleared or removed */\n",
" events.on('clear_output.CodeCell', handleClearOutput);\n",
" events.on('delete.Cell', handleClearOutput);\n",
"\n",
" /* Handle when a new output is added */\n",
" events.on('output_added.OutputArea', handleAddOutput);\n",
"\n",
" /**\n",
" * Register the mime type and append_mime function with output_area\n",
" */\n",
" OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
" /* Is output safe? */\n",
" safe: true,\n",
" /* Index of renderer in `output_area.display_order` */\n",
" index: 0\n",
" });\n",
" }\n",
"\n",
" // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
" if (root.Jupyter !== undefined) {\n",
" var events = require('base/js/events');\n",
" var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
"\n",
" if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
" register_renderer(events, OutputArea);\n",
" }\n",
" }\n",
"\n",
" \n",
" if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
" root._bokeh_timeout = Date.now() + 5000;\n",
" root._bokeh_failed_load = false;\n",
" }\n",
"\n",
" var NB_LOAD_WARNING = {'data': {'text/html':\n",
" \"<div style='background-color: #fdd'>\\n\"+\n",
" \"<p>\\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",
" \"</p>\\n\"+\n",
" \"<ul>\\n\"+\n",
" \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
" \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
" \"</ul>\\n\"+\n",
" \"<code>\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"</code>\\n\"+\n",
" \"</div>\"}};\n",
"\n",
" function display_loaded() {\n",
" var el = document.getElementById(\"6947\");\n",
" if (el != null) {\n",
" el.textContent = \"BokehJS is loading...\";\n",
" }\n",
" if (root.Bokeh !== undefined) {\n",
" if (el != null) {\n",
" el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
" }\n",
" } else if (Date.now() < root._bokeh_timeout) {\n",
" setTimeout(display_loaded, 100)\n",
" }\n",
" }\n",
"\n",
"\n",
" function run_callbacks() {\n",
" try {\n",
" root._bokeh_onload_callbacks.forEach(function(callback) {\n",
" if (callback != null)\n",
" callback();\n",
" });\n",
" } finally {\n",
" delete root._bokeh_onload_callbacks\n",
" }\n",
" console.debug(\"Bokeh: all callbacks have finished\");\n",
" }\n",
"\n",
" function load_libs(css_urls, js_urls, callback) {\n",
" if (css_urls == null) css_urls = [];\n",
" if (js_urls == null) js_urls = [];\n",
"\n",
" root._bokeh_onload_callbacks.push(callback);\n",
" if (root._bokeh_is_loading > 0) {\n",
" console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
" return null;\n",
" }\n",
" if (js_urls == null || js_urls.length === 0) {\n",
" run_callbacks();\n",
" return null;\n",
" }\n",
" console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
" root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
"\n",
" function on_load() {\n",
" root._bokeh_is_loading--;\n",
" if (root._bokeh_is_loading === 0) {\n",
" console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
" run_callbacks()\n",
" }\n",
" }\n",
"\n",
" function on_error() {\n",
" console.error(\"failed to load \" + url);\n",
" }\n",
"\n",
" for (var i = 0; i < css_urls.length; i++) {\n",
" var url = css_urls[i];\n",
" const element = document.createElement(\"link\");\n",
" element.onload = on_load;\n",
" element.onerror = on_error;\n",
" element.rel = \"stylesheet\";\n",
" element.type = \"text/css\";\n",
" element.href = url;\n",
" console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
" document.body.appendChild(element);\n",
" }\n",
"\n",
" const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.2.3.min.js\": \"T2yuo9Oe71Cz/I4X9Ac5+gpEa5a8PpJCDlqKYO0CfAuEszu1JrXLl8YugMqYe3sM\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.2.3.min.js\": \"98GDGJ0kOMCUMUePhksaQ/GYgB3+NH9h996V88sh3aOiUNX3N+fLXAtry6xctSZ6\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.2.3.min.js\": \"89bArO+nlbP3sgakeHjCo1JYxYR5wufVgA3IbUvDY+K7w4zyxJqssu7wVnfeKCq8\"};\n",
"\n",
" for (var i = 0; i < js_urls.length; i++) {\n",
" var url = js_urls[i];\n",
" var element = document.createElement('script');\n",
" element.onload = on_load;\n",
" element.onerror = on_error;\n",
" element.async = false;\n",
" element.src = url;\n",
" if (url in hashes) {\n",
" element.crossOrigin = \"anonymous\";\n",
" element.integrity = \"sha384-\" + hashes[url];\n",
" }\n",
" console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
" document.head.appendChild(element);\n",
" }\n",
" };\n",
"\n",
" function inject_raw_css(css) {\n",
" const element = document.createElement(\"style\");\n",
" element.appendChild(document.createTextNode(css));\n",
" document.body.appendChild(element);\n",
" }\n",
"\n",
" \n",
" var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.2.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.2.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.2.3.min.js\"];\n",
" var css_urls = [];\n",
" \n",
"\n",
" var inline_js = [\n",
" function(Bokeh) {\n",
" Bokeh.set_log_level(\"info\");\n",
" },\n",
" function(Bokeh) {\n",
" \n",
" \n",
" }\n",
" ];\n",
"\n",
" function run_inline_js() {\n",
" \n",
" if (root.Bokeh !== undefined || force === true) {\n",
" \n",
" for (var i = 0; i < inline_js.length; i++) {\n",
" inline_js[i].call(root, root.Bokeh);\n",
" }\n",
" if (force === true) {\n",
" display_loaded();\n",
" }} else if (Date.now() < root._bokeh_timeout) {\n",
" setTimeout(run_inline_js, 100);\n",
" } else if (!root._bokeh_failed_load) {\n",
" console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
" root._bokeh_failed_load = true;\n",
" } else if (force !== true) {\n",
" var cell = $(document.getElementById(\"6947\")).parents('.cell').data().cell;\n",
" cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
" }\n",
"\n",
" }\n",
"\n",
" if (root._bokeh_is_loading === 0) {\n",
" console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
" run_inline_js();\n",
" } else {\n",
" load_libs(css_urls, js_urls, function() {\n",
" console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
" run_inline_js();\n",
" });\n",
" }\n",
"}(window));"
],
"application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n function now() {\n return new Date();\n }\n\n var force = true;\n\n if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\n \n\n \n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n var NB_LOAD_WARNING = {'data': {'text/html':\n \"<div style='background-color: #fdd'>\\n\"+\n \"<p>\\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 \"</p>\\n\"+\n \"<ul>\\n\"+\n \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n \"<li>use INLINE resources instead, as so:</li>\\n\"+\n \"</ul>\\n\"+\n \"<code>\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"</code>\\n\"+\n \"</div>\"}};\n\n function display_loaded() {\n var el = document.getElementById(\"6947\");\n if (el != null) {\n el.textContent = \"BokehJS is loading...\";\n }\n if (root.Bokeh !== undefined) {\n if (el != null) {\n el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(display_loaded, 100)\n }\n }\n\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls == null || js_urls.length === 0) {\n run_callbacks();\n return null;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n\n function on_error() {\n console.error(\"failed to load \" + url);\n }\n\n for (var i = 0; i < css_urls.length; i++) {\n var url = css_urls[i];\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n }\n\n const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.2.3.min.js\": \"T2yuo9Oe71Cz/I4X9Ac5+gpEa5a8PpJCDlqKYO0CfAuEszu1JrXLl8YugMqYe3sM\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.2.3.min.js\": \"98GDGJ0kOMCUMUePhksaQ/GYgB3+NH9h996V88sh3aOiUNX3N+fLXAtry6xctSZ6\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.2.3.min.js\": \"89bArO+nlbP3sgakeHjCo1JYxYR5wufVgA3IbUvDY+K7w4zyxJqssu7wVnfeKCq8\"};\n\n for (var i = 0; i < js_urls.length; i++) {\n var url = js_urls[i];\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n if (url in hashes) {\n element.crossOrigin = \"anonymous\";\n element.integrity = \"sha384-\" + hashes[url];\n }\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n \n var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.2.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.2.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.2.3.min.js\"];\n var css_urls = [];\n \n\n var inline_js = [\n function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\n function(Bokeh) {\n \n \n }\n ];\n\n function run_inline_js() {\n \n if (root.Bokeh !== undefined || force === true) {\n \n for (var i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }\n if (force === true) {\n display_loaded();\n }} else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n } else if (force !== true) {\n var cell = $(document.getElementById(\"6947\")).parents('.cell').data().cell;\n cell.output_area.append_execute_result(NB_LOAD_WARNING)\n }\n\n }\n\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(css_urls, js_urls, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));"
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# import libraries\n",
"import pandas as pd\n",
"import geopandas as gpd\n",
"from geopandas.tools import sjoin\n",
"\n",
"\n",
"# Data\n",
"from collections import Counter\n",
"from math import pi\n",
"from bokeh.palettes import BuGn\n",
"from bokeh.transform import cumsum\n",
"\n",
"import pandas_bokeh\n",
"from bokeh.plotting import figure\n",
"from bokeh.io import output_notebook, show\n",
"from bokeh.models import ColumnDataSource\n",
"# Create Bokeh-Table with DataFrame:\n",
"from bokeh.models.widgets import DataTable, TableColumn\n",
"from bokeh.transform import dodge\n",
"from bokeh.transform import factor_cmap\n",
"from bokeh.palettes import Spectral6, Spectral10\n",
"pandas_bokeh.output_notebook()"
]
},
{
"cell_type": "markdown",
"id": "67acdaf7",
"metadata": {},
"source": [
"<a id='importData'></a>\n",
"## 1. Explore mock data"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "af7ea9f9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"../../datasets/processed/user_data/located_lg_data_point_v2.shp\r\n"
]
}
],
"source": [
"!ls ../../datasets/processed/user_data/located_lg_data_point_v2.shp"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "e348a36a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Material</th>\n",
" <th>Material d</th>\n",
" <th>Volume</th>\n",
" <th>Country</th>\n",
" <th>Address</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" <th>Location t</th>\n",
" <th>Accuracy</th>\n",
" <th>wr_mean</th>\n",
" <th>...</th>\n",
" <th>cr_median</th>\n",
" <th>cr_std</th>\n",
" <th>cr_min</th>\n",
" <th>cr_max</th>\n",
" <th>bio_mean</th>\n",
" <th>bio_median</th>\n",
" <th>bio_std</th>\n",
" <th>bio_min</th>\n",
" <th>bio_max</th>\n",
" <th>geometry</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Rubber</td>\n",
" <td>None</td>\n",
" <td>2400</td>\n",
" <td>China</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>1.686943</td>\n",
" <td>...</td>\n",
" <td>0.000000</td>\n",
" <td>8.849100e-11</td>\n",
" <td>0.000000</td>\n",
" <td>2.813154e-08</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>1.400000e-14</td>\n",
" <td>MULTIPOLYGON (((73.49973 39.38174, 73.50468 39...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Rubber</td>\n",
" <td>None</td>\n",
" <td>1300</td>\n",
" <td>Malaysia</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>226.718707</td>\n",
" <td>...</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>MULTIPOLYGON (((98.93721 5.68384, 98.93771 5.6...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Rubber</td>\n",
" <td>None</td>\n",
" <td>1000</td>\n",
" <td>United States</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>0.088295</td>\n",
" <td>...</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>MULTIPOLYGON (((-180.00000 51.79409, -180.0000...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Rubber</td>\n",
" <td>None</td>\n",
" <td>730</td>\n",
" <td>Japan</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>MULTIPOLYGON (((122.71418 24.44983, 122.71457 ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Rubber</td>\n",
" <td>None</td>\n",
" <td>490</td>\n",
" <td>India</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>45.279566</td>\n",
" <td>...</td>\n",
" <td>31.787052</td>\n",
" <td>1.153720e+04</td>\n",
" <td>-243.486969</td>\n",
" <td>6.503950e+05</td>\n",
" <td>2.728085e-08</td>\n",
" <td>4.168220e-10</td>\n",
" <td>7.774598e-08</td>\n",
" <td>-5.642630e-10</td>\n",
" <td>7.001327e-07</td>\n",
" <td>MULTIPOLYGON (((68.11138 23.60145, 68.13528 23...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 30 columns</p>\n",
"</div>"
],
"text/plain": [
" Material Material d Volume Country Address Latitude Longitude \\\n",
"0 Rubber None 2400 China None None None \n",
"1 Rubber None 1300 Malaysia None None None \n",
"2 Rubber None 1000 United States None None None \n",
"3 Rubber None 730 Japan None None None \n",
"4 Rubber None 490 India None None None \n",
"\n",
" Location t Accuracy wr_mean ... cr_median cr_std cr_min \\\n",
"0 Unknown Low 1.686943 ... 0.000000 8.849100e-11 0.000000 \n",
"1 Unknown Low 226.718707 ... 0.000000 0.000000e+00 0.000000 \n",
"2 Unknown Low 0.088295 ... 0.000000 0.000000e+00 0.000000 \n",
"3 Unknown Low NaN ... NaN NaN NaN \n",
"4 Unknown Low 45.279566 ... 31.787052 1.153720e+04 -243.486969 \n",
"\n",
" cr_max bio_mean bio_median bio_std bio_min \\\n",
"0 2.813154e-08 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 \n",
"1 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 \n",
"2 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 \n",
"3 NaN NaN NaN NaN NaN \n",
"4 6.503950e+05 2.728085e-08 4.168220e-10 7.774598e-08 -5.642630e-10 \n",
"\n",
" bio_max geometry \n",
"0 1.400000e-14 MULTIPOLYGON (((73.49973 39.38174, 73.50468 39... \n",
"1 0.000000e+00 MULTIPOLYGON (((98.93721 5.68384, 98.93771 5.6... \n",
"2 0.000000e+00 MULTIPOLYGON (((-180.00000 51.79409, -180.0000... \n",
"3 NaN MULTIPOLYGON (((122.71418 24.44983, 122.71457 ... \n",
"4 7.001327e-07 MULTIPOLYGON (((68.11138 23.60145, 68.13528 23... \n",
"\n",
"[5 rows x 30 columns]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mock_data = gpd.read_file('../../datasets/processed/processed_data/located_lg_data_polygon_v2_stats.shp')\n",
"mock_data.head()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "aaf7d701",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Material</th>\n",
" <th>Material d</th>\n",
" <th>Volume</th>\n",
" <th>Country</th>\n",
" <th>Address</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" <th>Location t</th>\n",
" <th>Accuracy</th>\n",
" <th>wr_mean</th>\n",
" <th>...</th>\n",
" <th>wr_imp_max</th>\n",
" <th>df_imp</th>\n",
" <th>df_imp_min</th>\n",
" <th>df_imp_max</th>\n",
" <th>cr_imp</th>\n",
" <th>cr_imp_min</th>\n",
" <th>cr_imp_max</th>\n",
" <th>bio_imp</th>\n",
" <th>bio_imp_min</th>\n",
" <th>bio_imp_max</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Rubber</td>\n",
" <td>None</td>\n",
" <td>2400</td>\n",
" <td>China</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>1.686943</td>\n",
" <td>...</td>\n",
" <td>1.409836e+05</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>6.672000e-10</td>\n",
" <td>0.000000</td>\n",
" <td>6.751570e-05</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>3.360000e-11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Rubber</td>\n",
" <td>None</td>\n",
" <td>1300</td>\n",
" <td>Malaysia</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>226.718707</td>\n",
" <td>...</td>\n",
" <td>2.533535e+06</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Rubber</td>\n",
" <td>None</td>\n",
" <td>1000</td>\n",
" <td>United States</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>0.088295</td>\n",
" <td>...</td>\n",
" <td>1.150512e+03</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Rubber</td>\n",
" <td>None</td>\n",
" <td>730</td>\n",
" <td>Japan</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Rubber</td>\n",
" <td>None</td>\n",
" <td>490</td>\n",
" <td>India</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>45.279566</td>\n",
" <td>...</td>\n",
" <td>1.437854e+06</td>\n",
" <td>71.314111</td>\n",
" <td>0.000085</td>\n",
" <td>1854.204938</td>\n",
" <td>6.405891e+05</td>\n",
" <td>-119308.614807</td>\n",
" <td>3.186936e+08</td>\n",
" <td>0.000013</td>\n",
" <td>-2.764889e-07</td>\n",
" <td>3.430650e-04</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 42 columns</p>\n",
"</div>"
],
"text/plain": [
" Material Material d Volume Country Address Latitude Longitude \\\n",
"0 Rubber None 2400 China None None None \n",
"1 Rubber None 1300 Malaysia None None None \n",
"2 Rubber None 1000 United States None None None \n",
"3 Rubber None 730 Japan None None None \n",
"4 Rubber None 490 India None None None \n",
"\n",
" Location t Accuracy wr_mean ... wr_imp_max df_imp df_imp_min \\\n",
"0 Unknown Low 1.686943 ... 1.409836e+05 NaN NaN \n",
"1 Unknown Low 226.718707 ... 2.533535e+06 NaN NaN \n",
"2 Unknown Low 0.088295 ... 1.150512e+03 NaN NaN \n",
"3 Unknown Low NaN ... NaN NaN NaN \n",
"4 Unknown Low 45.279566 ... 1.437854e+06 71.314111 0.000085 \n",
"\n",
" df_imp_max cr_imp cr_imp_min cr_imp_max bio_imp \\\n",
"0 NaN 6.672000e-10 0.000000 6.751570e-05 0.000000 \n",
"1 NaN 0.000000e+00 0.000000 0.000000e+00 0.000000 \n",
"2 NaN 0.000000e+00 0.000000 0.000000e+00 0.000000 \n",
"3 NaN NaN NaN NaN NaN \n",
"4 1854.204938 6.405891e+05 -119308.614807 3.186936e+08 0.000013 \n",
"\n",
" bio_imp_min bio_imp_max \n",
"0 0.000000e+00 3.360000e-11 \n",
"1 0.000000e+00 0.000000e+00 \n",
"2 0.000000e+00 0.000000e+00 \n",
"3 NaN NaN \n",
"4 -2.764889e-07 3.430650e-04 \n",
"\n",
"[5 rows x 42 columns]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## calulate impact\n",
"\n",
"\n",
"#calculate water risk impact\n",
"wr_impact = [row['Volume']*row['wr_mean'] for i,row in mock_data.iterrows()]\n",
"wr_impact_min = [row['Volume']*row['wr_min'] for i,row in mock_data.iterrows()]\n",
"wr_impact_max = [row['Volume']*row['wr_max'] for i,row in mock_data.iterrows()]\n",
"\n",
"#calculate deforestation impact\n",
"df_impact = [row['Volume']*row['df_mean'] for i,row in mock_data.iterrows()]\n",
"df_impact_min = [row['Volume']*row['df_min'] for i,row in mock_data.iterrows()]\n",
"df_impact_max = [row['Volume']*row['df_max'] for i,row in mock_data.iterrows()]\n",
"\n",
"#calculate carbon impacts\n",
"cr_impact = [row['Volume']*row['cr_mean'] for i,row in mock_data.iterrows()]\n",
"cr_impact_min = [row['Volume']*row['cr_min'] for i,row in mock_data.iterrows()]\n",
"cr_impact_max = [row['Volume']*row['cr_max'] for i,row in mock_data.iterrows()]\n",
"\n",
"#calculate biodiversity impacts\n",
"bio_impacts = [row['Volume']*row['bio_mean'] for i,row in mock_data.iterrows()]\n",
"bio_impacts_min = [row['Volume']*row['bio_min'] for i,row in mock_data.iterrows()]\n",
"bio_impacts_max = [row['Volume']*row['bio_max'] for i,row in mock_data.iterrows()]\n",
"\n",
"\n",
"##append to dataframe\n",
"mock_data['wr_imp']=wr_impact\n",
"mock_data['wr_imp_min']=wr_impact_min\n",
"mock_data['wr_imp_max']=wr_impact_max\n",
"mock_data['df_imp']=df_impact\n",
"mock_data['df_imp_min']=df_impact_min\n",
"mock_data['df_imp_max']=df_impact_max\n",
"mock_data['cr_imp']=cr_impact\n",
"mock_data['cr_imp_min']=cr_impact_min\n",
"mock_data['cr_imp_max']=cr_impact_max\n",
"mock_data['bio_imp']=bio_impacts\n",
"mock_data['bio_imp_min']=bio_impacts_min\n",
"mock_data['bio_imp_max']=bio_impacts_max\n",
"\n",
"\n",
"mock_data.head()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "0a8c6b14",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"<ipython-input-6-e9716a9ad9f0>:3: UserWarning: Column names longer than 10 characters will be truncated when saved to ESRI Shapefile.\n",
" mock_data.to_file('../../datasets/processed/processed_data/located_lg_data_polygon_v2_stats_impacts.shp',driver='ESRI Shapefile')\n"
]
}
],
"source": [
"#export dataframe\n",
"\n",
"mock_data.to_file('../../datasets/processed/processed_data/located_lg_data_polygon_v2_stats_impacts.shp',driver='ESRI Shapefile')"
]
},
{
"cell_type": "markdown",
"id": "c9e1cf01",
"metadata": {},
"source": [
"### General charts:\n",
"\n",
" - We can provide information about total volume bought by country or continent\n",
" - percentage of material provided - to see your top materials\n",
" - percentage of different types of locations - to see your general kowledge of your current supply chain\n",
" - top countries by material provided\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "92520e80",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>OBJECTID</th>\n",
" <th>CONTINENT</th>\n",
" <th>SQMI</th>\n",
" <th>SQKM</th>\n",
" <th>Shape_Leng</th>\n",
" <th>Shape_Area</th>\n",
" <th>geometry</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.0</td>\n",
" <td>Africa</td>\n",
" <td>1.158346e+07</td>\n",
" <td>3.000115e+07</td>\n",
" <td>426.208612</td>\n",
" <td>2559.073098</td>\n",
" <td>MULTIPOLYGON (((35.488 -21.685, 35.452 -21.787...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2.0</td>\n",
" <td>Asia</td>\n",
" <td>1.731728e+07</td>\n",
" <td>4.485173e+07</td>\n",
" <td>2331.623746</td>\n",
" <td>5432.085227</td>\n",
" <td>MULTIPOLYGON (((150.894 -10.649, 150.881 -10.6...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3.0</td>\n",
" <td>Australia</td>\n",
" <td>2.973612e+06</td>\n",
" <td>7.701651e+06</td>\n",
" <td>252.165311</td>\n",
" <td>695.539921</td>\n",
" <td>MULTIPOLYGON (((158.882 -54.711, 158.880 -54.7...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4.0</td>\n",
" <td>North America</td>\n",
" <td>9.339528e+06</td>\n",
" <td>2.418936e+07</td>\n",
" <td>3954.892430</td>\n",
" <td>3707.418684</td>\n",
" <td>MULTIPOLYGON (((-81.678 7.389, -81.649 7.384, ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5.0</td>\n",
" <td>Oceania</td>\n",
" <td>1.656787e+05</td>\n",
" <td>4.291076e+05</td>\n",
" <td>221.581942</td>\n",
" <td>42.565470</td>\n",
" <td>MULTIPOLYGON (((169.186 -52.577, 169.162 -52.5...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>6.0</td>\n",
" <td>South America</td>\n",
" <td>6.856255e+06</td>\n",
" <td>1.775769e+07</td>\n",
" <td>622.552582</td>\n",
" <td>1539.312933</td>\n",
" <td>MULTIPOLYGON (((-67.209 -55.891, -67.247 -55.8...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>7.0</td>\n",
" <td>Antarctica</td>\n",
" <td>4.754809e+06</td>\n",
" <td>1.231495e+07</td>\n",
" <td>1587.227698</td>\n",
" <td>6034.461899</td>\n",
" <td>MULTIPOLYGON (((51.803 -46.457, 51.721 -46.453...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>8.0</td>\n",
" <td>Europe</td>\n",
" <td>3.821854e+06</td>\n",
" <td>9.898597e+06</td>\n",
" <td>1596.706533</td>\n",
" <td>1444.638513</td>\n",
" <td>MULTIPOLYGON (((23.849 35.523, 23.971 35.515, ...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" OBJECTID CONTINENT SQMI SQKM Shape_Leng \\\n",
"0 1.0 Africa 1.158346e+07 3.000115e+07 426.208612 \n",
"1 2.0 Asia 1.731728e+07 4.485173e+07 2331.623746 \n",
"2 3.0 Australia 2.973612e+06 7.701651e+06 252.165311 \n",
"3 4.0 North America 9.339528e+06 2.418936e+07 3954.892430 \n",
"4 5.0 Oceania 1.656787e+05 4.291076e+05 221.581942 \n",
"5 6.0 South America 6.856255e+06 1.775769e+07 622.552582 \n",
"6 7.0 Antarctica 4.754809e+06 1.231495e+07 1587.227698 \n",
"7 8.0 Europe 3.821854e+06 9.898597e+06 1596.706533 \n",
"\n",
" Shape_Area geometry \n",
"0 2559.073098 MULTIPOLYGON (((35.488 -21.685, 35.452 -21.787... \n",
"1 5432.085227 MULTIPOLYGON (((150.894 -10.649, 150.881 -10.6... \n",
"2 695.539921 MULTIPOLYGON (((158.882 -54.711, 158.880 -54.7... \n",
"3 3707.418684 MULTIPOLYGON (((-81.678 7.389, -81.649 7.384, ... \n",
"4 42.565470 MULTIPOLYGON (((169.186 -52.577, 169.162 -52.5... \n",
"5 1539.312933 MULTIPOLYGON (((-67.209 -55.891, -67.247 -55.8... \n",
"6 6034.461899 MULTIPOLYGON (((51.803 -46.457, 51.721 -46.453... \n",
"7 1444.638513 MULTIPOLYGON (((23.849 35.523, 23.971 35.515, ... "
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"continents = gpd.read_file('../../datasets/raw/input_data_test/continents.shp')\n",
"continents"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "c532434d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>OBJECTID</th>\n",
" <th>CONTINENT</th>\n",
" <th>SQMI</th>\n",
" <th>SQKM</th>\n",
" <th>Shape_Leng</th>\n",
" <th>Shape_Area</th>\n",
" <th>geometry</th>\n",
" <th>index_right</th>\n",
" <th>Material</th>\n",
" <th>Material d</th>\n",
" <th>...</th>\n",
" <th>wr_imp_max</th>\n",
" <th>df_imp</th>\n",
" <th>df_imp_min</th>\n",
" <th>df_imp_max</th>\n",
" <th>cr_imp</th>\n",
" <th>cr_imp_min</th>\n",
" <th>cr_imp_max</th>\n",
" <th>bio_imp</th>\n",
" <th>bio_imp_min</th>\n",
" <th>bio_imp_max</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.0</td>\n",
" <td>Africa</td>\n",
" <td>1.158346e+07</td>\n",
" <td>3.000115e+07</td>\n",
" <td>426.208612</td>\n",
" <td>2559.073098</td>\n",
" <td>MULTIPOLYGON (((35.488 -21.685, 35.452 -21.787...</td>\n",
" <td>10</td>\n",
" <td>Rubber</td>\n",
" <td>None</td>\n",
" <td>...</td>\n",
" <td>2.723210e+06</td>\n",
" <td>-318.649197</td>\n",
" <td>-1226.595855</td>\n",
" <td>-99.844961</td>\n",
" <td>-1.013901e+06</td>\n",
" <td>-1.103721e+07</td>\n",
" <td>-397.438571</td>\n",
" <td>-0.000009</td>\n",
" <td>-0.000035</td>\n",
" <td>-0.000003</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.0</td>\n",
" <td>Africa</td>\n",
" <td>1.158346e+07</td>\n",
" <td>3.000115e+07</td>\n",
" <td>426.208612</td>\n",
" <td>2559.073098</td>\n",
" <td>MULTIPOLYGON (((35.488 -21.685, 35.452 -21.787...</td>\n",
" <td>7</td>\n",
" <td>Rubber</td>\n",
" <td>None</td>\n",
" <td>...</td>\n",
" <td>3.008742e+04</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.0</td>\n",
" <td>Africa</td>\n",
" <td>1.158346e+07</td>\n",
" <td>3.000115e+07</td>\n",
" <td>426.208612</td>\n",
" <td>2559.073098</td>\n",
" <td>MULTIPOLYGON (((35.488 -21.685, 35.452 -21.787...</td>\n",
" <td>45</td>\n",
" <td>Leather</td>\n",
" <td>None</td>\n",
" <td>...</td>\n",
" <td>2.766773e+07</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2.0</td>\n",
" <td>Asia</td>\n",
" <td>1.731728e+07</td>\n",
" <td>4.485173e+07</td>\n",
" <td>2331.623746</td>\n",
" <td>5432.085227</td>\n",
" <td>MULTIPOLYGON (((150.894 -10.649, 150.881 -10.6...</td>\n",
" <td>27</td>\n",
" <td>Cotton</td>\n",
" <td>None</td>\n",
" <td>...</td>\n",
" <td>2.753818e+06</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>8.0</td>\n",
" <td>Europe</td>\n",
" <td>3.821854e+06</td>\n",
" <td>9.898597e+06</td>\n",
" <td>1596.706533</td>\n",
" <td>1444.638513</td>\n",
" <td>MULTIPOLYGON (((23.849 35.523, 23.971 35.515, ...</td>\n",
" <td>27</td>\n",
" <td>Cotton</td>\n",
" <td>None</td>\n",
" <td>...</td>\n",
" <td>2.753818e+06</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 49 columns</p>\n",
"</div>"
],
"text/plain": [
" OBJECTID CONTINENT SQMI SQKM Shape_Leng Shape_Area \\\n",
"0 1.0 Africa 1.158346e+07 3.000115e+07 426.208612 2559.073098 \n",
"0 1.0 Africa 1.158346e+07 3.000115e+07 426.208612 2559.073098 \n",
"0 1.0 Africa 1.158346e+07 3.000115e+07 426.208612 2559.073098 \n",
"1 2.0 Asia 1.731728e+07 4.485173e+07 2331.623746 5432.085227 \n",
"7 8.0 Europe 3.821854e+06 9.898597e+06 1596.706533 1444.638513 \n",
"\n",
" geometry index_right Material \\\n",
"0 MULTIPOLYGON (((35.488 -21.685, 35.452 -21.787... 10 Rubber \n",
"0 MULTIPOLYGON (((35.488 -21.685, 35.452 -21.787... 7 Rubber \n",
"0 MULTIPOLYGON (((35.488 -21.685, 35.452 -21.787... 45 Leather \n",
"1 MULTIPOLYGON (((150.894 -10.649, 150.881 -10.6... 27 Cotton \n",
"7 MULTIPOLYGON (((23.849 35.523, 23.971 35.515, ... 27 Cotton \n",
"\n",
" Material d ... wr_imp_max df_imp df_imp_min df_imp_max \\\n",
"0 None ... 2.723210e+06 -318.649197 -1226.595855 -99.844961 \n",
"0 None ... 3.008742e+04 NaN NaN NaN \n",
"0 None ... 2.766773e+07 NaN NaN NaN \n",
"1 None ... 2.753818e+06 NaN NaN NaN \n",
"7 None ... 2.753818e+06 NaN NaN NaN \n",
"\n",
" cr_imp cr_imp_min cr_imp_max bio_imp bio_imp_min bio_imp_max \n",
"0 -1.013901e+06 -1.103721e+07 -397.438571 -0.000009 -0.000035 -0.000003 \n",
"0 0.000000e+00 0.000000e+00 0.000000 0.000000 0.000000 0.000000 \n",
"0 0.000000e+00 0.000000e+00 0.000000 0.000000 0.000000 0.000000 \n",
"1 0.000000e+00 0.000000e+00 0.000000 0.000000 0.000000 0.000000 \n",
"7 0.000000e+00 0.000000e+00 0.000000 0.000000 0.000000 0.000000 \n",
"\n",
"[5 rows x 49 columns]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## join dataframes for getting stats at continent level\n",
"join_df = sjoin(continents, mock_data, how=\"inner\")\n",
"join_df.head()"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "67de8ea1",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Country</th>\n",
" <th>OBJECTID</th>\n",
" <th>SQMI</th>\n",
" <th>SQKM</th>\n",
" <th>Shape_Leng</th>\n",
" <th>Shape_Area</th>\n",
" <th>index_right</th>\n",
" <th>Volume</th>\n",
" <th>wr_mean</th>\n",
" <th>wr_median</th>\n",
" <th>...</th>\n",
" <th>df_imp</th>\n",
" <th>df_imp_min</th>\n",
" <th>df_imp_max</th>\n",
" <th>cr_imp</th>\n",
" <th>cr_imp_min</th>\n",
" <th>cr_imp_max</th>\n",
" <th>bio_imp</th>\n",
" <th>bio_imp_min</th>\n",
" <th>bio_imp_max</th>\n",
" <th>geometry</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Argentina</td>\n",
" <td>6.0</td>\n",
" <td>6.856255e+06</td>\n",
" <td>1.775769e+07</td>\n",
" <td>622.552582</td>\n",
" <td>1539.312933</td>\n",
" <td>41</td>\n",
" <td>140</td>\n",
" <td>19440.327613</td>\n",
" <td>5754.687988</td>\n",
" <td>...</td>\n",
" <td>-1.786884e+05</td>\n",
" <td>-4.634443e+05</td>\n",
" <td>71831.791992</td>\n",
" <td>-1.950775e+07</td>\n",
" <td>-3.062715e+09</td>\n",
" <td>8.631285e+05</td>\n",
" <td>-1.845754e-03</td>\n",
" <td>-3.108784e-02</td>\n",
" <td>1.596102e-03</td>\n",
" <td>MULTIPOLYGON (((-73.56054 -49.94247, -73.56052...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Australia</td>\n",
" <td>43.0</td>\n",
" <td>5.934360e+07</td>\n",
" <td>1.536998e+08</td>\n",
" <td>9541.693325</td>\n",
" <td>26495.924796</td>\n",
" <td>403</td>\n",
" <td>17790</td>\n",
" <td>789720.133852</td>\n",
" <td>173274.990162</td>\n",
" <td>...</td>\n",
" <td>-4.035647e+07</td>\n",
" <td>-6.444621e+07</td>\n",
" <td>-71.914848</td>\n",
" <td>-7.183121e+09</td>\n",
" <td>-1.384068e+11</td>\n",
" <td>-5.572344e+03</td>\n",
" <td>-7.299327e-01</td>\n",
" <td>-9.130121e+00</td>\n",
" <td>-8.992352e-07</td>\n",
" <td>POLYGON ((149.30875 -29.35461, 149.31280 -29.3...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Australia</td>\n",
" <td>43.0</td>\n",
" <td>5.934360e+07</td>\n",
" <td>1.536998e+08</td>\n",
" <td>9541.693325</td>\n",
" <td>26495.924796</td>\n",
" <td>403</td>\n",
" <td>17790</td>\n",
" <td>789720.133852</td>\n",
" <td>173274.990162</td>\n",
" <td>...</td>\n",
" <td>-4.035647e+07</td>\n",
" <td>-6.444621e+07</td>\n",
" <td>-71.914848</td>\n",
" <td>-7.183121e+09</td>\n",
" <td>-1.384068e+11</td>\n",
" <td>-5.572344e+03</td>\n",
" <td>-7.299327e-01</td>\n",
" <td>-9.130121e+00</td>\n",
" <td>-8.992352e-07</td>\n",
" <td>MULTIPOLYGON (((72.24619 -53.02073, 72.24644 -...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Australia</td>\n",
" <td>43.0</td>\n",
" <td>5.934360e+07</td>\n",
" <td>1.536998e+08</td>\n",
" <td>9541.693325</td>\n",
" <td>26495.924796</td>\n",
" <td>403</td>\n",
" <td>17790</td>\n",
" <td>789720.133852</td>\n",
" <td>173274.990162</td>\n",
" <td>...</td>\n",
" <td>-4.035647e+07</td>\n",
" <td>-6.444621e+07</td>\n",
" <td>-71.914848</td>\n",
" <td>-7.183121e+09</td>\n",
" <td>-1.384068e+11</td>\n",
" <td>-5.572344e+03</td>\n",
" <td>-7.299327e-01</td>\n",
" <td>-9.130121e+00</td>\n",
" <td>-8.992352e-07</td>\n",
" <td>MULTIPOLYGON (((140.99926 -28.99910, 141.04221...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Bangladesh</td>\n",
" <td>2.0</td>\n",
" <td>1.731728e+07</td>\n",
" <td>4.485173e+07</td>\n",
" <td>2331.623746</td>\n",
" <td>5432.085227</td>\n",
" <td>16</td>\n",
" <td>1400</td>\n",
" <td>8.558963</td>\n",
" <td>6.088120</td>\n",
" <td>...</td>\n",
" <td>-5.223351e-01</td>\n",
" <td>-7.158305e+00</td>\n",
" <td>-0.003407</td>\n",
" <td>-1.630630e+04</td>\n",
" <td>-2.517929e+05</td>\n",
" <td>2.655120e+06</td>\n",
" <td>-2.151800e-08</td>\n",
" <td>-4.027660e-07</td>\n",
" <td>3.621667e-05</td>\n",
" <td>MULTIPOLYGON (((88.00791 24.66782, 88.02667 24...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 41 columns</p>\n",
"</div>"
],
"text/plain": [
" Country OBJECTID SQMI SQKM Shape_Leng \\\n",
"0 Argentina 6.0 6.856255e+06 1.775769e+07 622.552582 \n",
"1 Australia 43.0 5.934360e+07 1.536998e+08 9541.693325 \n",
"2 Australia 43.0 5.934360e+07 1.536998e+08 9541.693325 \n",
"3 Australia 43.0 5.934360e+07 1.536998e+08 9541.693325 \n",
"4 Bangladesh 2.0 1.731728e+07 4.485173e+07 2331.623746 \n",
"\n",
" Shape_Area index_right Volume wr_mean wr_median ... \\\n",
"0 1539.312933 41 140 19440.327613 5754.687988 ... \n",
"1 26495.924796 403 17790 789720.133852 173274.990162 ... \n",
"2 26495.924796 403 17790 789720.133852 173274.990162 ... \n",
"3 26495.924796 403 17790 789720.133852 173274.990162 ... \n",
"4 5432.085227 16 1400 8.558963 6.088120 ... \n",
"\n",
" df_imp df_imp_min df_imp_max cr_imp cr_imp_min \\\n",
"0 -1.786884e+05 -4.634443e+05 71831.791992 -1.950775e+07 -3.062715e+09 \n",
"1 -4.035647e+07 -6.444621e+07 -71.914848 -7.183121e+09 -1.384068e+11 \n",
"2 -4.035647e+07 -6.444621e+07 -71.914848 -7.183121e+09 -1.384068e+11 \n",
"3 -4.035647e+07 -6.444621e+07 -71.914848 -7.183121e+09 -1.384068e+11 \n",
"4 -5.223351e-01 -7.158305e+00 -0.003407 -1.630630e+04 -2.517929e+05 \n",
"\n",
" cr_imp_max bio_imp bio_imp_min bio_imp_max \\\n",
"0 8.631285e+05 -1.845754e-03 -3.108784e-02 1.596102e-03 \n",
"1 -5.572344e+03 -7.299327e-01 -9.130121e+00 -8.992352e-07 \n",
"2 -5.572344e+03 -7.299327e-01 -9.130121e+00 -8.992352e-07 \n",
"3 -5.572344e+03 -7.299327e-01 -9.130121e+00 -8.992352e-07 \n",
"4 2.655120e+06 -2.151800e-08 -4.027660e-07 3.621667e-05 \n",
"\n",
" geometry \n",
"0 MULTIPOLYGON (((-73.56054 -49.94247, -73.56052... \n",
"1 POLYGON ((149.30875 -29.35461, 149.31280 -29.3... \n",
"2 MULTIPOLYGON (((72.24619 -53.02073, 72.24644 -... \n",
"3 MULTIPOLYGON (((140.99926 -28.99910, 141.04221... \n",
"4 MULTIPOLYGON (((88.00791 24.66782, 88.02667 24... \n",
"\n",
"[5 rows x 41 columns]"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#group by country\n",
"countries_volume_df = join_df.groupby('Country').sum()\n",
"##add geometry\n",
"country_geoms = countries_volume_df.merge(country_geoms, right_on='Country',left_on='Country', how='inner').drop_duplicates()\n",
"\n",
"country_geoms.head()"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "2188ec29",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Country</th>\n",
" <th>OBJECTID</th>\n",
" <th>SQMI</th>\n",
" <th>SQKM</th>\n",
" <th>Shape_Leng</th>\n",
" <th>Shape_Area</th>\n",
" <th>index_right</th>\n",
" <th>Volume</th>\n",
" <th>wr_mean</th>\n",
" <th>wr_median</th>\n",
" <th>...</th>\n",
" <th>df_imp</th>\n",
" <th>df_imp_min</th>\n",
" <th>df_imp_max</th>\n",
" <th>cr_imp</th>\n",
" <th>cr_imp_min</th>\n",
" <th>cr_imp_max</th>\n",
" <th>bio_imp</th>\n",
" <th>bio_imp_min</th>\n",
" <th>bio_imp_max</th>\n",
" <th>geometry</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Argentina</td>\n",
" <td>6.0</td>\n",
" <td>6.856255e+06</td>\n",
" <td>1.775769e+07</td>\n",
" <td>622.552582</td>\n",
" <td>1539.312933</td>\n",
" <td>41</td>\n",
" <td>140</td>\n",
" <td>19440.327613</td>\n",
" <td>5754.687988</td>\n",
" <td>...</td>\n",
" <td>-1.786884e+05</td>\n",
" <td>-4.634443e+05</td>\n",
" <td>7.183179e+04</td>\n",
" <td>-1.950775e+07</td>\n",
" <td>-3.062715e+09</td>\n",
" <td>8.631285e+05</td>\n",
" <td>-1.845754e-03</td>\n",
" <td>-3.108784e-02</td>\n",
" <td>1.596102e-03</td>\n",
" <td>MULTIPOLYGON (((-73.56054 -49.94247, -73.56052...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Australia</td>\n",
" <td>43.0</td>\n",
" <td>5.934360e+07</td>\n",
" <td>1.536998e+08</td>\n",
" <td>9541.693325</td>\n",
" <td>26495.924796</td>\n",
" <td>403</td>\n",
" <td>17790</td>\n",
" <td>789720.133852</td>\n",
" <td>173274.990162</td>\n",
" <td>...</td>\n",
" <td>-4.035647e+07</td>\n",
" <td>-6.444621e+07</td>\n",
" <td>-7.191485e+01</td>\n",
" <td>-7.183121e+09</td>\n",
" <td>-1.384068e+11</td>\n",
" <td>-5.572344e+03</td>\n",
" <td>-7.299327e-01</td>\n",
" <td>-9.130121e+00</td>\n",
" <td>-8.992352e-07</td>\n",
" <td>POLYGON ((149.30875 -29.35461, 149.31280 -29.3...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Bangladesh</td>\n",
" <td>2.0</td>\n",
" <td>1.731728e+07</td>\n",
" <td>4.485173e+07</td>\n",
" <td>2331.623746</td>\n",
" <td>5432.085227</td>\n",
" <td>16</td>\n",
" <td>1400</td>\n",
" <td>8.558963</td>\n",
" <td>6.088120</td>\n",
" <td>...</td>\n",
" <td>-5.223351e-01</td>\n",
" <td>-7.158305e+00</td>\n",
" <td>-3.407447e-03</td>\n",
" <td>-1.630630e+04</td>\n",
" <td>-2.517929e+05</td>\n",
" <td>2.655120e+06</td>\n",
" <td>-2.151800e-08</td>\n",
" <td>-4.027660e-07</td>\n",
" <td>3.621667e-05</td>\n",
" <td>MULTIPOLYGON (((88.00791 24.66782, 88.02667 24...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Brazil</td>\n",
" <td>12.0</td>\n",
" <td>1.371251e+07</td>\n",
" <td>3.551538e+07</td>\n",
" <td>1245.105164</td>\n",
" <td>3078.625867</td>\n",
" <td>60</td>\n",
" <td>2080</td>\n",
" <td>17670.023677</td>\n",
" <td>3418.011529</td>\n",
" <td>...</td>\n",
" <td>-5.533917e+06</td>\n",
" <td>-1.740504e+07</td>\n",
" <td>-3.168394e-07</td>\n",
" <td>-1.899072e+09</td>\n",
" <td>-2.071599e+11</td>\n",
" <td>-1.054560e-09</td>\n",
" <td>-9.299721e-02</td>\n",
" <td>-1.320976e+01</td>\n",
" <td>0.000000e+00</td>\n",
" <td>MULTIPOLYGON (((-73.98306 -7.53473, -73.98303 ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Burundi</td>\n",
" <td>1.0</td>\n",
" <td>1.158346e+07</td>\n",
" <td>3.000115e+07</td>\n",
" <td>426.208612</td>\n",
" <td>2559.073098</td>\n",
" <td>45</td>\n",
" <td>680</td>\n",
" <td>40687.835938</td>\n",
" <td>40687.835938</td>\n",
" <td>...</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>POLYGON ((29.28880 -3.34510, 29.28942 -3.34421...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 41 columns</p>\n",
"</div>"
],
"text/plain": [
" Country OBJECTID SQMI SQKM Shape_Leng \\\n",
"0 Argentina 6.0 6.856255e+06 1.775769e+07 622.552582 \n",
"1 Australia 43.0 5.934360e+07 1.536998e+08 9541.693325 \n",
"4 Bangladesh 2.0 1.731728e+07 4.485173e+07 2331.623746 \n",
"5 Brazil 12.0 1.371251e+07 3.551538e+07 1245.105164 \n",
"6 Burundi 1.0 1.158346e+07 3.000115e+07 426.208612 \n",
"\n",
" Shape_Area index_right Volume wr_mean wr_median ... \\\n",
"0 1539.312933 41 140 19440.327613 5754.687988 ... \n",
"1 26495.924796 403 17790 789720.133852 173274.990162 ... \n",
"4 5432.085227 16 1400 8.558963 6.088120 ... \n",
"5 3078.625867 60 2080 17670.023677 3418.011529 ... \n",
"6 2559.073098 45 680 40687.835938 40687.835938 ... \n",
"\n",
" df_imp df_imp_min df_imp_max cr_imp cr_imp_min \\\n",
"0 -1.786884e+05 -4.634443e+05 7.183179e+04 -1.950775e+07 -3.062715e+09 \n",
"1 -4.035647e+07 -6.444621e+07 -7.191485e+01 -7.183121e+09 -1.384068e+11 \n",
"4 -5.223351e-01 -7.158305e+00 -3.407447e-03 -1.630630e+04 -2.517929e+05 \n",
"5 -5.533917e+06 -1.740504e+07 -3.168394e-07 -1.899072e+09 -2.071599e+11 \n",
"6 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 \n",
"\n",
" cr_imp_max bio_imp bio_imp_min bio_imp_max \\\n",
"0 8.631285e+05 -1.845754e-03 -3.108784e-02 1.596102e-03 \n",
"1 -5.572344e+03 -7.299327e-01 -9.130121e+00 -8.992352e-07 \n",
"4 2.655120e+06 -2.151800e-08 -4.027660e-07 3.621667e-05 \n",
"5 -1.054560e-09 -9.299721e-02 -1.320976e+01 0.000000e+00 \n",
"6 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 \n",
"\n",
" geometry \n",
"0 MULTIPOLYGON (((-73.56054 -49.94247, -73.56052... \n",
"1 POLYGON ((149.30875 -29.35461, 149.31280 -29.3... \n",
"4 MULTIPOLYGON (((88.00791 24.66782, 88.02667 24... \n",
"5 MULTIPOLYGON (((-73.98306 -7.53473, -73.98303 ... \n",
"6 POLYGON ((29.28880 -3.34510, 29.28942 -3.34421... \n",
"\n",
"[5 rows x 41 columns]"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"country_geoms = country_geoms.drop_duplicates(subset=['Country'])\n",
"country_geoms.head()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "e28419c9",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>CONTINENT</th>\n",
" <th>geometry</th>\n",
" <th>OBJECTID</th>\n",
" <th>SQMI</th>\n",
" <th>SQKM</th>\n",
" <th>Shape_Leng</th>\n",
" <th>Shape_Area</th>\n",
" <th>index_right</th>\n",
" <th>Volume</th>\n",
" <th>wr_mean</th>\n",
" <th>...</th>\n",
" <th>wr_imp_max</th>\n",
" <th>df_imp</th>\n",
" <th>df_imp_min</th>\n",
" <th>df_imp_max</th>\n",
" <th>cr_imp</th>\n",
" <th>cr_imp_min</th>\n",
" <th>cr_imp_max</th>\n",
" <th>bio_imp</th>\n",
" <th>bio_imp_min</th>\n",
" <th>bio_imp_max</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Africa</td>\n",
" <td>MULTIPOLYGON (((35.488 -21.685, 35.452 -21.787...</td>\n",
" <td>3.0</td>\n",
" <td>3.475039e+07</td>\n",
" <td>9.000345e+07</td>\n",
" <td>1278.625835</td>\n",
" <td>7677.219293</td>\n",
" <td>62</td>\n",
" <td>4080</td>\n",
" <td>40892.061220</td>\n",
" <td>...</td>\n",
" <td>3.042103e+07</td>\n",
" <td>-3.186492e+02</td>\n",
" <td>-1.226596e+03</td>\n",
" <td>-99.844961</td>\n",
" <td>-1.013901e+06</td>\n",
" <td>-1.103721e+07</td>\n",
" <td>-3.974386e+02</td>\n",
" <td>-0.000009</td>\n",
" <td>-0.000035</td>\n",
" <td>-2.865552e-06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Asia</td>\n",
" <td>MULTIPOLYGON (((150.894 -10.649, 150.881 -10.6...</td>\n",
" <td>62.0</td>\n",
" <td>5.368357e+08</td>\n",
" <td>1.390404e+09</td>\n",
" <td>72280.336121</td>\n",
" <td>168394.642052</td>\n",
" <td>592</td>\n",
" <td>54805</td>\n",
" <td>214176.870475</td>\n",
" <td>...</td>\n",
" <td>7.442242e+09</td>\n",
" <td>-4.257004e+06</td>\n",
" <td>-8.669441e+06</td>\n",
" <td>435598.901801</td>\n",
" <td>-3.805358e+08</td>\n",
" <td>-2.836014e+10</td>\n",
" <td>3.486245e+09</td>\n",
" <td>-0.046769</td>\n",
" <td>-1.805112</td>\n",
" <td>7.272118e-02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Australia</td>\n",
" <td>MULTIPOLYGON (((158.882 -54.711, 158.880 -54.7...</td>\n",
" <td>15.0</td>\n",
" <td>1.486806e+07</td>\n",
" <td>3.850826e+07</td>\n",
" <td>1260.826554</td>\n",
" <td>3477.699603</td>\n",
" <td>187</td>\n",
" <td>8640</td>\n",
" <td>501915.788946</td>\n",
" <td>...</td>\n",
" <td>1.888118e+10</td>\n",
" <td>-3.045522e+07</td>\n",
" <td>-4.656496e+07</td>\n",
" <td>-71.913369</td>\n",
" <td>-5.800737e+09</td>\n",
" <td>-5.667104e+10</td>\n",
" <td>-5.219470e+03</td>\n",
" <td>-0.593691</td>\n",
" <td>-3.807598</td>\n",
" <td>-8.992352e-07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>North America</td>\n",
" <td>MULTIPOLYGON (((-81.678 7.389, -81.649 7.384, ...</td>\n",
" <td>20.0</td>\n",
" <td>4.669764e+07</td>\n",
" <td>1.209468e+08</td>\n",
" <td>19774.462151</td>\n",
" <td>18537.093420</td>\n",
" <td>131</td>\n",
" <td>8925</td>\n",
" <td>57259.365618</td>\n",
" <td>...</td>\n",
" <td>5.409882e+08</td>\n",
" <td>-9.700556e+03</td>\n",
" <td>-9.841648e+04</td>\n",
" <td>0.000000</td>\n",
" <td>-2.044440e+07</td>\n",
" <td>-1.272256e+09</td>\n",
" <td>0.000000e+00</td>\n",
" <td>-0.000242</td>\n",
" <td>-0.012346</td>\n",
" <td>0.000000e+00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Oceania</td>\n",
" <td>MULTIPOLYGON (((169.186 -52.577, 169.162 -52.5...</td>\n",
" <td>25.0</td>\n",
" <td>8.283936e+05</td>\n",
" <td>2.145538e+06</td>\n",
" <td>1107.909709</td>\n",
" <td>212.827352</td>\n",
" <td>131</td>\n",
" <td>8850</td>\n",
" <td>123182.034024</td>\n",
" <td>...</td>\n",
" <td>2.919394e+09</td>\n",
" <td>-3.300416e+06</td>\n",
" <td>-5.960416e+06</td>\n",
" <td>-0.000493</td>\n",
" <td>-4.607949e+08</td>\n",
" <td>-2.724525e+10</td>\n",
" <td>-1.176247e+02</td>\n",
" <td>-0.045414</td>\n",
" <td>-1.774174</td>\n",
" <td>0.000000e+00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 41 columns</p>\n",
"</div>"
],
"text/plain": [
" CONTINENT geometry OBJECTID \\\n",
"0 Africa MULTIPOLYGON (((35.488 -21.685, 35.452 -21.787... 3.0 \n",
"1 Asia MULTIPOLYGON (((150.894 -10.649, 150.881 -10.6... 62.0 \n",
"2 Australia MULTIPOLYGON (((158.882 -54.711, 158.880 -54.7... 15.0 \n",
"3 North America MULTIPOLYGON (((-81.678 7.389, -81.649 7.384, ... 20.0 \n",
"4 Oceania MULTIPOLYGON (((169.186 -52.577, 169.162 -52.5... 25.0 \n",
"\n",
" SQMI SQKM Shape_Leng Shape_Area index_right \\\n",
"0 3.475039e+07 9.000345e+07 1278.625835 7677.219293 62 \n",
"1 5.368357e+08 1.390404e+09 72280.336121 168394.642052 592 \n",
"2 1.486806e+07 3.850826e+07 1260.826554 3477.699603 187 \n",
"3 4.669764e+07 1.209468e+08 19774.462151 18537.093420 131 \n",
"4 8.283936e+05 2.145538e+06 1107.909709 212.827352 131 \n",
"\n",
" Volume wr_mean ... wr_imp_max df_imp df_imp_min \\\n",
"0 4080 40892.061220 ... 3.042103e+07 -3.186492e+02 -1.226596e+03 \n",
"1 54805 214176.870475 ... 7.442242e+09 -4.257004e+06 -8.669441e+06 \n",
"2 8640 501915.788946 ... 1.888118e+10 -3.045522e+07 -4.656496e+07 \n",
"3 8925 57259.365618 ... 5.409882e+08 -9.700556e+03 -9.841648e+04 \n",
"4 8850 123182.034024 ... 2.919394e+09 -3.300416e+06 -5.960416e+06 \n",
"\n",
" df_imp_max cr_imp cr_imp_min cr_imp_max bio_imp \\\n",
"0 -99.844961 -1.013901e+06 -1.103721e+07 -3.974386e+02 -0.000009 \n",
"1 435598.901801 -3.805358e+08 -2.836014e+10 3.486245e+09 -0.046769 \n",
"2 -71.913369 -5.800737e+09 -5.667104e+10 -5.219470e+03 -0.593691 \n",
"3 0.000000 -2.044440e+07 -1.272256e+09 0.000000e+00 -0.000242 \n",
"4 -0.000493 -4.607949e+08 -2.724525e+10 -1.176247e+02 -0.045414 \n",
"\n",
" bio_imp_min bio_imp_max \n",
"0 -0.000035 -2.865552e-06 \n",
"1 -1.805112 7.272118e-02 \n",
"2 -3.807598 -8.992352e-07 \n",
"3 -0.012346 0.000000e+00 \n",
"4 -1.774174 0.000000e+00 \n",
"\n",
"[5 rows x 41 columns]"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#group by continent\n",
"#group by country\n",
"continents_volume_df = join_df.groupby('CONTINENT').sum()\n",
"#add geometry\n",
"continents_geom = continents[['CONTINENT','geometry']].merge(continents_volume_df, right_on='CONTINENT',left_on='CONTINENT', how='inner' )\n",
"\n",
"continents_geom.head()"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "dc3cf6ea",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"<ipython-input-37-2c963b657ff0>:2: UserWarning: Column names longer than 10 characters will be truncated when saved to ESRI Shapefile.\n",
" country_geoms.to_file('../../datasets/processed/processed_data/test_vis/country_sum.shp', driver='ESRI Shapefile')\n",
"<ipython-input-37-2c963b657ff0>:3: UserWarning: Column names longer than 10 characters will be truncated when saved to ESRI Shapefile.\n",
" continents_geom.to_file('../../datasets/processed/processed_data/test_vis/continents_sum.shp', driver='ESRI Shapefile')\n"
]
}
],
"source": [
"#export for visualizatuon in qgis\n",
"country_geoms.to_file('../../datasets/processed/processed_data/test_vis/country_sum.shp', driver='ESRI Shapefile')\n",
"continents_geom.to_file('../../datasets/processed/processed_data/test_vis/continents_sum.shp', driver='ESRI Shapefile')"
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "3b1f10a0",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Country</th>\n",
" <th>OBJECTID</th>\n",
" <th>SQMI</th>\n",
" <th>SQKM</th>\n",
" <th>Shape_Leng</th>\n",
" <th>Shape_Area</th>\n",
" <th>index_right</th>\n",
" <th>Volume</th>\n",
" <th>wr_mean</th>\n",
" <th>wr_median</th>\n",
" <th>...</th>\n",
" <th>df_imp</th>\n",
" <th>df_imp_min</th>\n",
" <th>df_imp_max</th>\n",
" <th>cr_imp</th>\n",
" <th>cr_imp_min</th>\n",
" <th>cr_imp_max</th>\n",
" <th>bio_imp</th>\n",
" <th>bio_imp_min</th>\n",
" <th>bio_imp_max</th>\n",
" <th>geometry</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>Canada</td>\n",
" <td>4.0</td>\n",
" <td>9.339528e+06</td>\n",
" <td>2.418936e+07</td>\n",
" <td>3954.892430</td>\n",
" <td>3707.418684</td>\n",
" <td>42</td>\n",
" <td>125</td>\n",
" <td>29975.149161</td>\n",
" <td>13345.055664</td>\n",
" <td>...</td>\n",
" <td>-9700.556284</td>\n",
" <td>-98416.481018</td>\n",
" <td>0.000000</td>\n",
" <td>-2.044440e+07</td>\n",
" <td>-1.272256e+09</td>\n",
" <td>0.000000e+00</td>\n",
" <td>-0.000242</td>\n",
" <td>-0.012346</td>\n",
" <td>0.000000</td>\n",
" <td>MULTIPOLYGON (((-141.00275 69.70417, -141.0027...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Argentina</td>\n",
" <td>6.0</td>\n",
" <td>6.856255e+06</td>\n",
" <td>1.775769e+07</td>\n",
" <td>622.552582</td>\n",
" <td>1539.312933</td>\n",
" <td>41</td>\n",
" <td>140</td>\n",
" <td>19440.327613</td>\n",
" <td>5754.687988</td>\n",
" <td>...</td>\n",
" <td>-178688.436217</td>\n",
" <td>-463444.262695</td>\n",
" <td>71831.791992</td>\n",
" <td>-1.950775e+07</td>\n",
" <td>-3.062715e+09</td>\n",
" <td>8.631285e+05</td>\n",
" <td>-0.001846</td>\n",
" <td>-0.031088</td>\n",
" <td>0.001596</td>\n",
" <td>MULTIPOLYGON (((-73.56054 -49.94247, -73.56052...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>Korea</td>\n",
" <td>2.0</td>\n",
" <td>1.731728e+07</td>\n",
" <td>4.485173e+07</td>\n",
" <td>2331.623746</td>\n",
" <td>5432.085227</td>\n",
" <td>37</td>\n",
" <td>160</td>\n",
" <td>409.754392</td>\n",
" <td>163.833557</td>\n",
" <td>...</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>MULTIPOLYGON (((124.37273 37.90986, 124.37350 ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31</th>\n",
" <td>Uzbekistan</td>\n",
" <td>2.0</td>\n",
" <td>1.731728e+07</td>\n",
" <td>4.485173e+07</td>\n",
" <td>2331.623746</td>\n",
" <td>5432.085227</td>\n",
" <td>23</td>\n",
" <td>600</td>\n",
" <td>147.928929</td>\n",
" <td>28.563921</td>\n",
" <td>...</td>\n",
" <td>98.808917</td>\n",
" <td>0.327866</td>\n",
" <td>305.552316</td>\n",
" <td>2.646718e+05</td>\n",
" <td>0.000000e+00</td>\n",
" <td>1.726761e+06</td>\n",
" <td>0.000004</td>\n",
" <td>0.000000</td>\n",
" <td>0.000014</td>\n",
" <td>MULTIPOLYGON (((55.99890 44.43675, 55.99893 45...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Burundi</td>\n",
" <td>1.0</td>\n",
" <td>1.158346e+07</td>\n",
" <td>3.000115e+07</td>\n",
" <td>426.208612</td>\n",
" <td>2559.073098</td>\n",
" <td>45</td>\n",
" <td>680</td>\n",
" <td>40687.835938</td>\n",
" <td>40687.835938</td>\n",
" <td>...</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>POLYGON ((29.28880 -3.34510, 29.28942 -3.34421...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 41 columns</p>\n",
"</div>"
],
"text/plain": [
" Country OBJECTID SQMI SQKM Shape_Leng \\\n",
"7 Canada 4.0 9.339528e+06 2.418936e+07 3954.892430 \n",
"0 Argentina 6.0 6.856255e+06 1.775769e+07 622.552582 \n",
"21 Korea 2.0 1.731728e+07 4.485173e+07 2331.623746 \n",
"31 Uzbekistan 2.0 1.731728e+07 4.485173e+07 2331.623746 \n",
"6 Burundi 1.0 1.158346e+07 3.000115e+07 426.208612 \n",
"\n",
" Shape_Area index_right Volume wr_mean wr_median ... \\\n",
"7 3707.418684 42 125 29975.149161 13345.055664 ... \n",
"0 1539.312933 41 140 19440.327613 5754.687988 ... \n",
"21 5432.085227 37 160 409.754392 163.833557 ... \n",
"31 5432.085227 23 600 147.928929 28.563921 ... \n",
"6 2559.073098 45 680 40687.835938 40687.835938 ... \n",
"\n",
" df_imp df_imp_min df_imp_max cr_imp cr_imp_min \\\n",
"7 -9700.556284 -98416.481018 0.000000 -2.044440e+07 -1.272256e+09 \n",
"0 -178688.436217 -463444.262695 71831.791992 -1.950775e+07 -3.062715e+09 \n",
"21 0.000000 0.000000 0.000000 0.000000e+00 0.000000e+00 \n",
"31 98.808917 0.327866 305.552316 2.646718e+05 0.000000e+00 \n",
"6 0.000000 0.000000 0.000000 0.000000e+00 0.000000e+00 \n",
"\n",
" cr_imp_max bio_imp bio_imp_min bio_imp_max \\\n",
"7 0.000000e+00 -0.000242 -0.012346 0.000000 \n",
"0 8.631285e+05 -0.001846 -0.031088 0.001596 \n",
"21 0.000000e+00 0.000000 0.000000 0.000000 \n",
"31 1.726761e+06 0.000004 0.000000 0.000014 \n",
"6 0.000000e+00 0.000000 0.000000 0.000000 \n",
"\n",
" geometry \n",
"7 MULTIPOLYGON (((-141.00275 69.70417, -141.0027... \n",
"0 MULTIPOLYGON (((-73.56054 -49.94247, -73.56052... \n",
"21 MULTIPOLYGON (((124.37273 37.90986, 124.37350 ... \n",
"31 MULTIPOLYGON (((55.99890 44.43675, 55.99893 45... \n",
"6 POLYGON ((29.28880 -3.34510, 29.28942 -3.34421... \n",
"\n",
"[5 rows x 41 columns]"
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"country_geoms = country_geoms.sort_values('Volume', ascending=True)\n",
"country_geoms.head()"
]
},
{
"cell_type": "code",
"execution_count": 74,
"id": "1da616ec",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" <div class=\"bk-root\" id=\"0d78d603-f0c1-43b3-8c88-2051af6d139d\" data-root-id=\"2257\"></div>\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"(function(root) {\n",
" function embed_document(root) {\n",
" \n",
" var docs_json = {\"5016ce18-6c8d-4608-89c9-b06504245aed\":{\"roots\":{\"references\":[{\"attributes\":{\"children\":[{\"id\":\"2256\"},{\"id\":\"2254\"}]},\"id\":\"2257\",\"type\":\"Column\"},{\"attributes\":{\"axis\":{\"id\":\"2202\"},\"dimension\":1,\"grid_line_color\":null,\"ticker\":null},\"id\":\"2204\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2194\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"2196\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"2220\",\"type\":\"LinearScale\"},{\"attributes\":{\"toolbar\":{\"id\":\"2255\"},\"toolbar_location\":\"above\"},\"id\":\"2256\",\"type\":\"ToolbarBox\"},{\"attributes\":{\"factors\":[\"Canada\",\"Argentina\",\"Korea\",\"Uzbekistan\",\"Burundi\",\"Japan\",\"Italy\",\"Cote d'Ivoire\",\"Bangladesh\",\"Malaysia\",\"Brazil\",\"Liberia\",\"Turkey\",\"Indonesia\",\"United States\",\"Vietnam\",\"India\",\"Thailand\",\"Greece\",\"United states\",\"Australia\",\"China\"],\"range_padding\":0.1},\"id\":\"2218\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"2240\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"2248\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"range\":{\"id\":\"2192\"}},\"id\":\"2206\",\"type\":\"Dodge\"},{\"attributes\":{\"formatter\":{\"id\":\"2250\"},\"ticker\":{\"id\":\"2225\"}},\"id\":\"2224\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data_source\":{\"id\":\"2186\"},\"glyph\":{\"id\":\"2208\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"2209\"},\"selection_glyph\":null,\"view\":{\"id\":\"2211\"}},\"id\":\"2210\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2225\",\"type\":\"BasicTicker\"},{\"attributes\":{\"below\":[{\"id\":\"2224\"}],\"center\":[{\"id\":\"2227\"},{\"id\":\"2230\"}],\"left\":[{\"id\":\"2228\"}],\"plot_width\":450,\"renderers\":[{\"id\":\"2236\"}],\"title\":{\"id\":\"2214\"},\"toolbar\":{\"id\":\"2231\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"2216\"},\"x_scale\":{\"id\":\"2220\"},\"y_range\":{\"id\":\"2218\"},\"y_scale\":{\"id\":\"2222\"}},\"id\":\"2213\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"formatter\":{\"id\":\"2242\"},\"ticker\":{\"id\":\"2199\"}},\"id\":\"2198\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data_source\":{\"id\":\"2212\"},\"glyph\":{\"id\":\"2234\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"2235\"},\"selection_glyph\":null,\"view\":{\"id\":\"2237\"}},\"id\":\"2236\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2244\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\"},\"id\":\"2231\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_color\":{\"value\":\"#c9d9d3\"},\"height\":{\"value\":0.2},\"line_color\":{\"value\":\"#c9d9d3\"},\"right\":{\"field\":\"volume\"},\"y\":{\"field\":\"country\",\"transform\":{\"id\":\"2206\"}}},\"id\":\"2208\",\"type\":\"HBar\"},{\"attributes\":{\"text\":\"Top countries by volume (%)\"},\"id\":\"2214\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2243\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"2199\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"2251\",\"type\":\"Selection\"},{\"attributes\":{\"axis\":{\"id\":\"2198\"},\"ticker\":null},\"id\":\"2201\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"2248\"},\"ticker\":{\"id\":\"2229\"}},\"id\":\"2228\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"axis\":{\"id\":\"2228\"},\"dimension\":1,\"grid_line_color\":null,\"ticker\":null},\"id\":\"2230\",\"type\":\"Grid\"},{\"attributes\":{\"text\":\"Top countries by volume (Tonnes)\"},\"id\":\"2188\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2203\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"end\":100},\"id\":\"2216\",\"type\":\"Range1d\"},{\"attributes\":{},\"id\":\"2252\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"children\":[[{\"id\":\"2187\"},0,0],[{\"id\":\"2213\"},0,1]]},\"id\":\"2254\",\"type\":\"GridBox\"},{\"attributes\":{\"axis\":{\"id\":\"2224\"},\"ticker\":null},\"id\":\"2227\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2229\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"factors\":[\"Canada\",\"Argentina\",\"Korea\",\"Uzbekistan\",\"Burundi\",\"Japan\",\"Italy\",\"Cote d'Ivoire\",\"Bangladesh\",\"Malaysia\",\"Brazil\",\"Liberia\",\"Turkey\",\"Indonesia\",\"United States\",\"Vietnam\",\"India\",\"Thailand\",\"Greece\",\"United states\",\"Australia\",\"China\"],\"range_padding\":0.1},\"id\":\"2192\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"2222\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"2242\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"range\":{\"id\":\"2192\"}},\"id\":\"2232\",\"type\":\"Dodge\"},{\"attributes\":{\"data\":{\"country\":[\"Canada\",\"Argentina\",\"Korea\",\"Uzbekistan\",\"Burundi\",\"Japan\",\"Italy\",\"Cote d'Ivoire\",\"Bangladesh\",\"Malaysia\",\"Brazil\",\"Liberia\",\"Turkey\",\"Indonesia\",\"United States\",\"Vietnam\",\"India\",\"Thailand\",\"Greece\",\"United states\",\"Australia\",\"China\"],\"volume\":[125,140,160,600,680,730,790,1100,1400,2040,2080,2300,2400,2600,3600,3670,4235,5020,6600,11000,17790,26800]},\"selected\":{\"id\":\"2243\"},\"selection_policy\":{\"id\":\"2244\"}},\"id\":\"2186\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_color\":{\"value\":\"#c9d9d3\"},\"height\":{\"value\":0.2},\"line_color\":{\"value\":\"#c9d9d3\"},\"right\":{\"field\":\"volume_pct\"},\"y\":{\"field\":\"country\",\"transform\":{\"id\":\"2232\"}}},\"id\":\"2234\",\"type\":\"HBar\"},{\"attributes\":{\"source\":{\"id\":\"2186\"}},\"id\":\"2211\",\"type\":\"CDSView\"},{\"attributes\":{\"data\":{\"country\":[\"Canada\",\"Argentina\",\"Korea\",\"Uzbekistan\",\"Burundi\",\"Japan\",\"Italy\",\"Cote d'Ivoire\",\"Bangladesh\",\"Malaysia\",\"Brazil\",\"Liberia\",\"Turkey\",\"Indonesia\",\"United States\",\"Vietnam\",\"India\",\"Thailand\",\"Greece\",\"United states\",\"Australia\",\"China\"],\"volume_pct\":[0.13,0.15,0.17,0.63,0.71,0.76,0.82,1.15,1.46,2.13,2.17,2.4,2.5,2.71,3.76,3.83,4.42,5.24,6.89,11.48,18.56,27.96]},\"selected\":{\"id\":\"2251\"},\"selection_policy\":{\"id\":\"2252\"}},\"id\":\"2212\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\"},\"id\":\"2205\",\"type\":\"Toolbar\"},{\"attributes\":{\"below\":[{\"id\":\"2198\"}],\"center\":[{\"id\":\"2201\"},{\"id\":\"2204\"}],\"left\":[{\"id\":\"2202\"}],\"plot_width\":450,\"renderers\":[{\"id\":\"2210\"}],\"title\":{\"id\":\"2188\"},\"toolbar\":{\"id\":\"2205\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"2190\"},\"x_scale\":{\"id\":\"2194\"},\"y_range\":{\"id\":\"2192\"},\"y_scale\":{\"id\":\"2196\"}},\"id\":\"2187\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"end\":26800},\"id\":\"2190\",\"type\":\"Range1d\"},{\"attributes\":{\"toolbars\":[{\"id\":\"2205\"},{\"id\":\"2231\"}]},\"id\":\"2255\",\"type\":\"ProxyToolbar\"},{\"attributes\":{\"formatter\":{\"id\":\"2240\"},\"ticker\":{\"id\":\"2203\"}},\"id\":\"2202\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"source\":{\"id\":\"2212\"}},\"id\":\"2237\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"2250\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#c9d9d3\"},\"height\":{\"value\":0.2},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#c9d9d3\"},\"right\":{\"field\":\"volume_pct\"},\"y\":{\"field\":\"country\",\"transform\":{\"id\":\"2232\"}}},\"id\":\"2235\",\"type\":\"HBar\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#c9d9d3\"},\"height\":{\"value\":0.2},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#c9d9d3\"},\"right\":{\"field\":\"volume\"},\"y\":{\"field\":\"country\",\"transform\":{\"id\":\"2206\"}}},\"id\":\"2209\",\"type\":\"HBar\"}],\"root_ids\":[\"2257\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
" var render_items = [{\"docid\":\"5016ce18-6c8d-4608-89c9-b06504245aed\",\"root_ids\":[\"2257\"],\"roots\":{\"2257\":\"0d78d603-f0c1-43b3-8c88-2051af6d139d\"}}];\n",
" root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
"\n",
" }\n",
" if (root.Bokeh !== undefined) {\n",
" embed_document(root);\n",
" } else {\n",
" var attempts = 0;\n",
" var timer = setInterval(function(root) {\n",
" if (root.Bokeh !== undefined) {\n",
" clearInterval(timer);\n",
" embed_document(root);\n",
" } else {\n",
" attempts++;\n",
" if (attempts > 100) {\n",
" clearInterval(timer);\n",
" console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
" }\n",
" }\n",
" }, 10, root)\n",
" }\n",
"})(window);"
],
"application/vnd.bokehjs_exec.v0+json": ""
},
"metadata": {
"application/vnd.bokehjs_exec.v0+json": {
"id": "2257"
}
},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div style=\"display: table;\"><div style=\"display: table-row;\"><div style=\"display: table-cell;\"><b title=\"bokeh.models.layouts.Column\">Column</b>(</div><div style=\"display: table-cell;\">id = '2257', <span id=\"2424\" style=\"cursor: pointer;\">…)</span></div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">align = 'start',</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">aspect_ratio = None,</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">background = None,</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">children = [ToolbarBox(id='2256', ...), GridBox(id='2254', ...)],</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">css_classes = [],</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">disabled = False,</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">height = None,</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">height_policy = 'auto',</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_event_callbacks = {},</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_property_callbacks = {},</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">margin = (0, 0, 0, 0),</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">max_height = None,</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">max_width = None,</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">min_height = None,</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">min_width = None,</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">name = None,</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">rows = 'auto',</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">sizing_mode = None,</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">spacing = 0,</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">subscribed_events = [],</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">tags = [],</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">visible = True,</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">width = None,</div></div><div class=\"2423\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">width_policy = 'auto')</div></div></div>\n",
"<script>\n",
"(function() {\n",
" var expanded = false;\n",
" var ellipsis = document.getElementById(\"2424\");\n",
" ellipsis.addEventListener(\"click\", function() {\n",
" var rows = document.getElementsByClassName(\"2423\");\n",
" for (var i = 0; i < rows.length; i++) {\n",
" var el = rows[i];\n",
" el.style.display = expanded ? \"none\" : \"table-row\";\n",
" }\n",
" ellipsis.innerHTML = expanded ? \"…)\" : \"‹‹‹\";\n",
" expanded = !expanded;\n",
" });\n",
"})();\n",
"</script>\n"
],
"text/plain": [
"Column(id='2257', ...)"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"country = list(country_geoms['Country'])\n",
"volume = list(country_geoms['Volume'])\n",
"\n",
"#represent top countries by volume\n",
"data = {'country': country,\n",
" 'volume': volume}\n",
"\n",
"source = ColumnDataSource(data)\n",
"\n",
"p = figure(y_range=country, x_range=(0, 26800), plot_width=250, title=\"Top countries by volume (Tonnes)\",\n",
" toolbar_location=None, tools=\"\")\n",
"\n",
"p.hbar(y=dodge('country', 0, range=p.y_range), right='volume', height=0.2, source=source,\n",
" color=\"#c9d9d3\")\n",
"\n",
"p.y_range.range_padding = 0.1\n",
"p.ygrid.grid_line_color = None\n",
"\n",
"#represent top countries by percentage\n",
"volume_pct = [round((val*100)/sum(volume),2) for val in volume]\n",
"\n",
"data_pct = {'country': country,\n",
" 'volume_pct': volume_pct}\n",
"\n",
"source_pct = ColumnDataSource(data_pct)\n",
"\n",
"p_pct = figure(y_range=country, x_range=(0, 100), plot_width=250, title=\"Top countries by volume (%)\",\n",
" toolbar_location=None, tools=\"\")\n",
"\n",
"p_pct.hbar(y=dodge('country', 0, range=p.y_range), right='volume_pct', height=0.2, source=source_pct,\n",
" color=\"#c9d9d3\")\n",
"\n",
"p_pct.y_range.range_padding = 0.1\n",
"p_pct.ygrid.grid_line_color = None\n",
"\n",
"\n",
"\n",
"#Make Dashboard with Grid Layout:\n",
"pandas_bokeh.plot_grid([[p, p_pct]], plot_width=450)"
]
},
{
"cell_type": "markdown",
"id": "0e5d46b0",
"metadata": {},
"source": [
"## by material:"
]
},
{
"cell_type": "code",
"execution_count": 119,
"id": "5f58c061",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" <div class=\"bk-root\" id=\"6e2ed7a3-7e72-4eb5-90d5-ee30a58aa0af\" data-root-id=\"2712\"></div>\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"(function(root) {\n",
" function embed_document(root) {\n",
" \n",
" var docs_json = {\"3922598e-5285-4bc0-b475-220edc612857\":{\"roots\":{\"references\":[{\"attributes\":{\"children\":[{\"id\":\"2711\"},{\"id\":\"2709\"}]},\"id\":\"2712\",\"type\":\"Column\"},{\"attributes\":{},\"id\":\"2697\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"data\":{\"Volume\":[48745,8155,19510],\"__x__values\":[0,1,2],\"__x__values_original\":[\"Cotton\",\"Leather\",\"Rubber\"]},\"selected\":{\"id\":\"2687\"},\"selection_policy\":{\"id\":\"2688\"}},\"id\":\"2641\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"2649\",\"type\":\"LinearScale\"},{\"attributes\":{\"code\":\"\\n var labels = {0: 'Cotton', 1: 'Leather', 2: 'Rubber'};\\n return labels[tick];\\n \"},\"id\":\"2675\",\"type\":\"FuncTickFormatter\"},{\"attributes\":{\"axis_label\":\"Material\",\"formatter\":{\"id\":\"2675\"},\"ticker\":{\"id\":\"2694\"}},\"id\":\"2653\",\"type\":\"LinearAxis\"},{\"attributes\":{\"axis\":{\"id\":\"2657\"},\"dimension\":1,\"ticker\":null},\"id\":\"2660\",\"type\":\"Grid\"},{\"attributes\":{\"columns\":[{\"id\":\"2601\"},{\"id\":\"2602\"}],\"height\":300,\"source\":{\"id\":\"2603\"},\"view\":{\"id\":\"2605\"}},\"id\":\"2604\",\"type\":\"DataTable\"},{\"attributes\":{},\"id\":\"2665\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"2647\",\"type\":\"DataRange1d\"},{\"attributes\":{\"toolbar\":{\"id\":\"2710\"},\"toolbar_location\":\"above\"},\"id\":\"2711\",\"type\":\"ToolbarBox\"},{\"attributes\":{\"editor\":{\"id\":\"2701\"},\"field\":\"volume\",\"formatter\":{\"id\":\"2700\"},\"title\":\"volume\"},\"id\":\"2602\",\"type\":\"TableColumn\"},{\"attributes\":{},\"id\":\"2645\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"2698\",\"type\":\"StringFormatter\"},{\"attributes\":{\"ticks\":[0,1,2]},\"id\":\"2694\",\"type\":\"FixedTicker\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":{\"id\":\"2662\"},\"active_tap\":\"auto\",\"tools\":[{\"id\":\"2661\"},{\"id\":\"2662\"},{\"id\":\"2663\"},{\"id\":\"2664\"},{\"id\":\"2665\"},{\"id\":\"2666\"},{\"id\":\"2692\"}]},\"id\":\"2668\",\"type\":\"Toolbar\"},{\"attributes\":{\"source\":{\"id\":\"2603\"}},\"id\":\"2605\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"2701\",\"type\":\"StringEditor\"},{\"attributes\":{\"children\":[[{\"id\":\"2604\"},0,0],[{\"id\":\"2642\"},0,1]]},\"id\":\"2709\",\"type\":\"GridBox\"},{\"attributes\":{\"text\":\"Total volume purchased by Material\"},\"id\":\"2643\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2688\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2699\",\"type\":\"StringEditor\"},{\"attributes\":{\"below\":[{\"id\":\"2653\"}],\"center\":[{\"id\":\"2656\"},{\"id\":\"2660\"},{\"id\":\"2690\"}],\"left\":[{\"id\":\"2657\"}],\"output_backend\":\"webgl\",\"plot_height\":350,\"plot_width\":300,\"renderers\":[{\"id\":\"2681\"}],\"sizing_mode\":\"fixed\",\"title\":{\"id\":\"2643\"},\"toolbar\":{\"id\":\"2668\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"2645\"},\"x_scale\":{\"id\":\"2649\"},\"y_range\":{\"id\":\"2647\"},\"y_scale\":{\"id\":\"2651\"}},\"id\":\"2642\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"2651\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"2685\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"toolbars\":[{\"id\":\"2668\"}],\"tools\":[{\"id\":\"2661\"},{\"id\":\"2662\"},{\"id\":\"2663\"},{\"id\":\"2664\"},{\"id\":\"2665\"},{\"id\":\"2666\"},{\"id\":\"2692\"}]},\"id\":\"2710\",\"type\":\"ProxyToolbar\"},{\"attributes\":{\"overlay\":{\"id\":\"2667\"}},\"id\":\"2663\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"2700\",\"type\":\"StringFormatter\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"line_width\":{\"value\":2},\"top\":{\"field\":\"Volume\"},\"width\":{\"value\":0.7},\"x\":{\"field\":\"__x__values\",\"transform\":{\"id\":\"2677\"}}},\"id\":\"2679\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2658\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"2661\",\"type\":\"PanTool\"},{\"attributes\":{\"source\":{\"id\":\"2641\"}},\"id\":\"2682\",\"type\":\"CDSView\"},{\"attributes\":{\"range\":{\"id\":\"2645\"}},\"id\":\"2677\",\"type\":\"Dodge\"},{\"attributes\":{},\"id\":\"2666\",\"type\":\"HelpTool\"},{\"attributes\":{\"callback\":null,\"mode\":\"vline\",\"renderers\":[{\"id\":\"2681\"}],\"tooltips\":[[\"Material\",\"@__x__values_original\"],[\"Volume\",\"@{Volume}\"]]},\"id\":\"2692\",\"type\":\"HoverTool\"},{\"attributes\":{\"label\":{\"value\":\" Volume\"},\"renderers\":[{\"id\":\"2681\"}]},\"id\":\"2691\",\"type\":\"LegendItem\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"line_width\":{\"value\":2},\"top\":{\"field\":\"Volume\"},\"width\":{\"value\":0.7},\"x\":{\"field\":\"__x__values\",\"transform\":{\"id\":\"2677\"}}},\"id\":\"2680\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2687\",\"type\":\"Selection\"},{\"attributes\":{\"axis\":{\"id\":\"2653\"},\"ticker\":null},\"id\":\"2656\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2662\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"click_policy\":\"hide\",\"items\":[{\"id\":\"2691\"}]},\"id\":\"2690\",\"type\":\"Legend\"},{\"attributes\":{\"data\":{\"index\":[0,1,2],\"materials\":[\"Cotton\",\"Leather\",\"Rubber\"],\"volume\":[48745,8155,19510]},\"selected\":{\"id\":\"2696\"},\"selection_policy\":{\"id\":\"2697\"}},\"id\":\"2603\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"2667\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"data_source\":{\"id\":\"2641\"},\"glyph\":{\"id\":\"2679\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"2680\"},\"selection_glyph\":null,\"view\":{\"id\":\"2682\"}},\"id\":\"2681\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2696\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"2664\",\"type\":\"SaveTool\"},{\"attributes\":{\"axis_label\":\"Volume\",\"formatter\":{\"id\":\"2685\"},\"ticker\":{\"id\":\"2658\"}},\"id\":\"2657\",\"type\":\"LinearAxis\"},{\"attributes\":{\"editor\":{\"id\":\"2699\"},\"field\":\"materials\",\"formatter\":{\"id\":\"2698\"},\"title\":\"materials\"},\"id\":\"2601\",\"type\":\"TableColumn\"}],\"root_ids\":[\"2712\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
" var render_items = [{\"docid\":\"3922598e-5285-4bc0-b475-220edc612857\",\"root_ids\":[\"2712\"],\"roots\":{\"2712\":\"6e2ed7a3-7e72-4eb5-90d5-ee30a58aa0af\"}}];\n",
" root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
"\n",
" }\n",
" if (root.Bokeh !== undefined) {\n",
" embed_document(root);\n",
" } else {\n",
" var attempts = 0;\n",
" var timer = setInterval(function(root) {\n",
" if (root.Bokeh !== undefined) {\n",
" clearInterval(timer);\n",
" embed_document(root);\n",
" } else {\n",
" attempts++;\n",
" if (attempts > 100) {\n",
" clearInterval(timer);\n",
" console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
" }\n",
" }\n",
" }, 10, root)\n",
" }\n",
"})(window);"
],
"application/vnd.bokehjs_exec.v0+json": ""
},
"metadata": {
"application/vnd.bokehjs_exec.v0+json": {
"id": "2712"
}
},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div style=\"display: table;\"><div style=\"display: table-row;\"><div style=\"display: table-cell;\"><b title=\"bokeh.models.layouts.Column\">Column</b>(</div><div style=\"display: table-cell;\">id = '2712', <span id=\"2786\" style=\"cursor: pointer;\">…)</span></div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">align = 'start',</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">aspect_ratio = None,</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">background = None,</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">children = [ToolbarBox(id='2711', ...), GridBox(id='2709', ...)],</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">css_classes = [],</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">disabled = False,</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">height = None,</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">height_policy = 'auto',</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_event_callbacks = {},</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_property_callbacks = {},</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">margin = (0, 0, 0, 0),</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">max_height = None,</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">max_width = None,</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">min_height = None,</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">min_width = None,</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">name = None,</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">rows = 'auto',</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">sizing_mode = None,</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">spacing = 0,</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">subscribed_events = [],</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">tags = [],</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">visible = True,</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">width = None,</div></div><div class=\"2785\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">width_policy = 'auto')</div></div></div>\n",
"<script>\n",
"(function() {\n",
" var expanded = false;\n",
" var ellipsis = document.getElementById(\"2786\");\n",
" ellipsis.addEventListener(\"click\", function() {\n",
" var rows = document.getElementsByClassName(\"2785\");\n",
" for (var i = 0; i < rows.length; i++) {\n",
" var el = rows[i];\n",
" el.style.display = expanded ? \"none\" : \"table-row\";\n",
" }\n",
" ellipsis.innerHTML = expanded ? \"…)\" : \"‹‹‹\";\n",
" expanded = !expanded;\n",
" });\n",
"})();\n",
"</script>\n"
],
"text/plain": [
"Column(id='2712', ...)"
]
},
"execution_count": 119,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#group by materials\n",
"#group by material\n",
"risk_material = mock_data.groupby('Material').sum()\n",
"\n",
"## volume dataframe\n",
"materials = list(risk_material.index)\n",
"volumens = list(risk_material['Volume'])\n",
"df = gpd.GeoDataFrame()\n",
"df['materials']=materials\n",
"df['volume']=volumens# Create Bokeh-Table with DataFrame:\n",
"from bokeh.models.widgets import DataTable, TableColumn\n",
"from bokeh.models import ColumnDataSource\n",
"\n",
"data_table = DataTable(\n",
" columns=[TableColumn(field=Ci, title=Ci) for Ci in df.columns],\n",
" source=ColumnDataSource(df),\n",
" height=300,\n",
")\n",
"\n",
"p_bar = risk_material[['Volume']].plot_bokeh(\n",
" kind='bar',\n",
" title=\"Total volume purchased by Material\",\n",
" show_figure=False,\n",
") \n",
"\n",
"#Combine Table and Scatterplot via grid layout:\n",
"pandas_bokeh.plot_grid([[data_table, p_bar]], plot_width=300, plot_height=350)"
]
},
{
"cell_type": "code",
"execution_count": 126,
"id": "505e9149",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" <div class=\"bk-root\" id=\"4ec4321f-caed-4833-b7f8-da72cb384bd1\" data-root-id=\"3109\"></div>\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"(function(root) {\n",
" function embed_document(root) {\n",
" \n",
" var docs_json = {\"0b26ca6c-584a-48c2-b03e-9652ab4d80f6\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"3120\"}],\"center\":[{\"id\":\"3123\"},{\"id\":\"3127\"},{\"id\":\"3146\"}],\"left\":[{\"id\":\"3124\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"3137\"}],\"title\":{\"id\":\"3110\"},\"toolbar\":{\"id\":\"3129\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"3112\"},\"x_scale\":{\"id\":\"3116\"},\"y_range\":{\"id\":\"3114\"},\"y_scale\":{\"id\":\"3118\"}},\"id\":\"3109\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"axis_label\":null,\"formatter\":{\"id\":\"3143\"},\"ticker\":{\"id\":\"3121\"},\"visible\":false},\"id\":\"3120\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"3116\",\"type\":\"LinearScale\"},{\"attributes\":{\"axis\":{\"id\":\"3124\"},\"dimension\":1,\"grid_line_color\":null,\"ticker\":null},\"id\":\"3127\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"3112\",\"type\":\"DataRange1d\"},{\"attributes\":{\"end_angle\":{\"expr\":{\"id\":\"3132\"},\"units\":\"rad\"},\"fill_color\":{\"field\":\"color\"},\"inner_radius\":{\"units\":\"data\",\"value\":0.2},\"line_color\":{\"value\":\"white\"},\"outer_radius\":{\"units\":\"data\",\"value\":0.4},\"start_angle\":{\"expr\":{\"id\":\"3131\"},\"units\":\"rad\"},\"x\":{\"value\":0},\"y\":{\"value\":1}},\"id\":\"3135\",\"type\":\"AnnularWedge\"},{\"attributes\":{\"text\":\"Purchased volume by material (tonnes)\"},\"id\":\"3110\",\"type\":\"Title\"},{\"attributes\":{\"end_angle\":{\"expr\":{\"id\":\"3132\"},\"units\":\"rad\"},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"color\"},\"inner_radius\":{\"units\":\"data\",\"value\":0.2},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"outer_radius\":{\"units\":\"data\",\"value\":0.4},\"start_angle\":{\"expr\":{\"id\":\"3131\"},\"units\":\"rad\"},\"x\":{\"value\":0},\"y\":{\"value\":1}},\"id\":\"3136\",\"type\":\"AnnularWedge\"},{\"attributes\":{},\"id\":\"3145\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"field\":\"angle\",\"include_zero\":true},\"id\":\"3131\",\"type\":\"CumSum\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"Commodity\",\"@Commodity\"],[\"Value\",\"@value\"]]},\"id\":\"3128\",\"type\":\"HoverTool\"},{\"attributes\":{\"axis_label\":null,\"formatter\":{\"id\":\"3141\"},\"ticker\":{\"id\":\"3125\"},\"visible\":false},\"id\":\"3124\",\"type\":\"LinearAxis\"},{\"attributes\":{\"label\":{\"field\":\"Commodity\"},\"renderers\":[{\"id\":\"3137\"}]},\"id\":\"3147\",\"type\":\"LegendItem\"},{\"attributes\":{\"data\":{\"Commodity\":[\"Cotton\",\"Rubber\",\"Leather\"],\"angle\":{\"__ndarray__\":\"JDIspX4IEEBehkS5O6v5P9/KNgZudeU/\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[3]},\"color\":[\"#2ca25f\",\"#99d8c9\",\"#e5f5f9\"],\"index\":[\"0\",\"1\",\"2\"],\"value\":[48745,19510,8155]},\"selected\":{\"id\":\"3144\"},\"selection_policy\":{\"id\":\"3145\"}},\"id\":\"3133\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"field\":\"angle\"},\"id\":\"3132\",\"type\":\"CumSum\"},{\"attributes\":{\"axis\":{\"id\":\"3120\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"3123\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"3114\",\"type\":\"DataRange1d\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"3128\"}]},\"id\":\"3129\",\"type\":\"Toolbar\"},{\"attributes\":{\"data_source\":{\"id\":\"3133\"},\"glyph\":{\"id\":\"3135\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"3136\"},\"selection_glyph\":null,\"view\":{\"id\":\"3138\"}},\"id\":\"3137\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"3143\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"3118\",\"type\":\"LinearScale\"},{\"attributes\":{\"source\":{\"id\":\"3133\"}},\"id\":\"3138\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"3144\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"3125\",\"type\":\"BasicTicker\"},{\"attributes\":{\"items\":[{\"id\":\"3147\"}]},\"id\":\"3146\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"3141\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"3121\",\"type\":\"BasicTicker\"}],\"root_ids\":[\"3109\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
" var render_items = [{\"docid\":\"0b26ca6c-584a-48c2-b03e-9652ab4d80f6\",\"root_ids\":[\"3109\"],\"roots\":{\"3109\":\"4ec4321f-caed-4833-b7f8-da72cb384bd1\"}}];\n",
" root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
"\n",
" }\n",
" if (root.Bokeh !== undefined) {\n",
" embed_document(root);\n",
" } else {\n",
" var attempts = 0;\n",
" var timer = setInterval(function(root) {\n",
" if (root.Bokeh !== undefined) {\n",
" clearInterval(timer);\n",
" embed_document(root);\n",
" } else {\n",
" attempts++;\n",
" if (attempts > 100) {\n",
" clearInterval(timer);\n",
" console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
" }\n",
" }\n",
" }, 10, root)\n",
" }\n",
"})(window);"
],
"application/vnd.bokehjs_exec.v0+json": ""
},
"metadata": {
"application/vnd.bokehjs_exec.v0+json": {
"id": "3109"
}
},
"output_type": "display_data"
}
],
"source": [
"\n",
"\n",
"x = Counter({\n",
" 'Cotton': 48745, 'Rubber': 19510, 'Leather': 8155\n",
"})\n",
"\n",
"data = pd.DataFrame.from_dict(dict(x), orient='index').reset_index().rename(index=str, columns={0:'value', 'index':'Commodity'})\n",
"data['angle'] = data['value']/sum(x.values()) * 2*pi\n",
"data['color'] = BuGn[len(x)]\n",
"\n",
"# Plotting code\n",
"\n",
"p = figure(plot_height=350, title=\"Purchased volume by material (tonnes)\", toolbar_location=None,\n",
" tools=\"hover\", tooltips=[(\"Commodity\", \"@Commodity\"),(\"Value\", \"@value\")])\n",
"\n",
"p.annular_wedge(x=0, y=1, inner_radius=0.2, outer_radius=0.4,\n",
" start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'),\n",
" line_color=\"white\", fill_color='color', legend='Commodity', source=data)\n",
"\n",
"p.axis.axis_label=None\n",
"p.axis.visible=False\n",
"p.grid.grid_line_color = None\n",
"\n",
"show(p)"
]
},
{
"cell_type": "code",
"execution_count": 134,
"id": "fcb96683",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th>Volume</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Country</th>\n",
" <th>Material</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Canada</th>\n",
" <th>Leather</th>\n",
" <td>125</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Argentina</th>\n",
" <th>Leather</th>\n",
" <td>140</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Korea</th>\n",
" <th>Leather</th>\n",
" <td>160</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Thailand</th>\n",
" <th>Leather</th>\n",
" <td>180</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Vietnam</th>\n",
" <th>Leather</th>\n",
" <td>260</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Brazil</th>\n",
" <th>Leather</th>\n",
" <td>480</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Uzbekistan</th>\n",
" <th>Cotton</th>\n",
" <td>600</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Burundi</th>\n",
" <th>Leather</th>\n",
" <td>680</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Japan</th>\n",
" <th>Rubber</th>\n",
" <td>730</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Italy</th>\n",
" <th>Leather</th>\n",
" <td>790</td>\n",
" </tr>\n",
" <tr>\n",
" <th>United States</th>\n",
" <th>Leather</th>\n",
" <td>800</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Vietnam</th>\n",
" <th>Rubber</th>\n",
" <td>810</td>\n",
" </tr>\n",
" <tr>\n",
" <th>United States</th>\n",
" <th>Rubber</th>\n",
" <td>1000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Cote d'Ivoire</th>\n",
" <th>Rubber</th>\n",
" <td>1100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Turkey</th>\n",
" <th>Cotton</th>\n",
" <td>1200</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Bangladesh</th>\n",
" <th>Cotton</th>\n",
" <td>1400</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Brazil</th>\n",
" <th>Cotton</th>\n",
" <td>1600</td>\n",
" </tr>\n",
" <tr>\n",
" <th>India</th>\n",
" <th>Rubber</th>\n",
" <td>1690</td>\n",
" </tr>\n",
" <tr>\n",
" <th>China</th>\n",
" <th>Leather</th>\n",
" <td>1800</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Malaysia</th>\n",
" <th>Rubber</th>\n",
" <td>2040</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Liberia</th>\n",
" <th>Rubber</th>\n",
" <td>2300</td>\n",
" </tr>\n",
" <tr>\n",
" <th>China</th>\n",
" <th>Rubber</th>\n",
" <td>2400</td>\n",
" </tr>\n",
" <tr>\n",
" <th>India</th>\n",
" <th>Cotton</th>\n",
" <td>2545</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Vietnam</th>\n",
" <th>Cotton</th>\n",
" <td>2600</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Indonesia</th>\n",
" <th>Rubber</th>\n",
" <td>2600</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Australia</th>\n",
" <th>Leather</th>\n",
" <td>2740</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Greece</th>\n",
" <th>Cotton</th>\n",
" <td>3300</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Thailand</th>\n",
" <th>Rubber</th>\n",
" <td>4840</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Australia</th>\n",
" <th>Cotton</th>\n",
" <td>5900</td>\n",
" </tr>\n",
" <tr>\n",
" <th>United states</th>\n",
" <th>Cotton</th>\n",
" <td>7000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>China</th>\n",
" <th>Cotton</th>\n",
" <td>22600</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Volume\n",
"Country Material \n",
"Canada Leather 125\n",
"Argentina Leather 140\n",
"Korea Leather 160\n",
"Thailand Leather 180\n",
"Vietnam Leather 260\n",
"Brazil Leather 480\n",
"Uzbekistan Cotton 600\n",
"Burundi Leather 680\n",
"Japan Rubber 730\n",
"Italy Leather 790\n",
"United States Leather 800\n",
"Vietnam Rubber 810\n",
"United States Rubber 1000\n",
"Cote d'Ivoire Rubber 1100\n",
"Turkey Cotton 1200\n",
"Bangladesh Cotton 1400\n",
"Brazil Cotton 1600\n",
"India Rubber 1690\n",
"China Leather 1800\n",
"Malaysia Rubber 2040\n",
"Liberia Rubber 2300\n",
"China Rubber 2400\n",
"India Cotton 2545\n",
"Vietnam Cotton 2600\n",
"Indonesia Rubber 2600\n",
"Australia Leather 2740\n",
"Greece Cotton 3300\n",
"Thailand Rubber 4840\n",
"Australia Cotton 5900\n",
"United states Cotton 7000\n",
"China Cotton 22600"
]
},
"execution_count": 134,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#group by material and country\n",
"group_m_c = mock_data.groupby(['Country','Material']).sum()[['Volume']].sort_values('Volume')\n",
"group_m_c"
]
},
{
"cell_type": "code",
"execution_count": 171,
"id": "b10799e1",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"BokehUserWarning: ColumnDataSource's columns must be of the same length. Current lengths: ('cotton', 21), ('countries', 22), ('leather', 21), ('rubber', 21)\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" <div class=\"bk-root\" id=\"910eb92f-3407-4a8c-a787-758f7dca5ae6\" data-root-id=\"4107\"></div>\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"(function(root) {\n",
" function embed_document(root) {\n",
" \n",
" var docs_json = {\"75d1a69e-bc84-467f-baa0-3fea72f06b91\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"4118\"}],\"center\":[{\"id\":\"4121\"},{\"id\":\"4124\"}],\"left\":[{\"id\":\"4122\"}],\"plot_width\":400,\"renderers\":[{\"id\":\"4130\"},{\"id\":\"4136\"},{\"id\":\"4142\"}],\"title\":{\"id\":\"4108\"},\"toolbar\":{\"id\":\"4125\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"4110\"},\"x_scale\":{\"id\":\"4114\"},\"y_range\":{\"id\":\"4112\"},\"y_scale\":{\"id\":\"4116\"}},\"id\":\"4107\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"source\":{\"id\":\"4106\"}},\"id\":\"4131\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#e84d60\"},\"height\":{\"value\":0.2},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#e84d60\"},\"right\":{\"field\":\"leather\"},\"y\":{\"field\":\"countries\",\"transform\":{\"id\":\"4138\"}}},\"id\":\"4141\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"4185\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"source\":{\"id\":\"4106\"}},\"id\":\"4143\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_color\":{\"value\":\"#718dbf\"},\"height\":{\"value\":0.2},\"line_color\":{\"value\":\"#718dbf\"},\"right\":{\"field\":\"rubber\"},\"y\":{\"field\":\"countries\",\"transform\":{\"id\":\"4132\"}}},\"id\":\"4134\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"4181\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#718dbf\"},\"height\":{\"value\":0.2},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#718dbf\"},\"right\":{\"field\":\"rubber\"},\"y\":{\"field\":\"countries\",\"transform\":{\"id\":\"4132\"}}},\"id\":\"4135\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"4183\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"4123\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"range\":{\"id\":\"4112\"},\"value\":0.25},\"id\":\"4138\",\"type\":\"Dodge\"},{\"attributes\":{\"formatter\":{\"id\":\"4183\"},\"ticker\":{\"id\":\"4119\"}},\"id\":\"4118\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data_source\":{\"id\":\"4106\"},\"glyph\":{\"id\":\"4134\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"4135\"},\"selection_glyph\":null,\"view\":{\"id\":\"4137\"}},\"id\":\"4136\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"formatter\":{\"id\":\"4181\"},\"ticker\":{\"id\":\"4123\"}},\"id\":\"4122\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"axis\":{\"id\":\"4118\"},\"ticker\":null},\"id\":\"4121\",\"type\":\"Grid\"},{\"attributes\":{\"data_source\":{\"id\":\"4106\"},\"glyph\":{\"id\":\"4140\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"4141\"},\"selection_glyph\":null,\"view\":{\"id\":\"4143\"}},\"id\":\"4142\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"factors\":[\"United States\",\"Malaysia\",\"Uzbekistan\",\"Greece\",\"Canada\",\"Argentina\",\"Brazil\",\"China\",\"Bangladesh\",\"Cote d'Ivoire\",\"Liberia\",\"Turkey\",\"Vietnam\",\"Burundi\",\"Thailand\",\"Australia\",\"India\",\"Korea\",\"Italy\",\"Indonesia\",\"United states\",\"Japan\"],\"range_padding\":0.1},\"id\":\"4112\",\"type\":\"FactorRange\"},{\"attributes\":{\"range\":{\"id\":\"4112\"},\"value\":-0.25},\"id\":\"4126\",\"type\":\"Dodge\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#c9d9d3\"},\"height\":{\"value\":0.2},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#c9d9d3\"},\"right\":{\"field\":\"cotton\"},\"y\":{\"field\":\"countries\",\"transform\":{\"id\":\"4126\"}}},\"id\":\"4129\",\"type\":\"HBar\"},{\"attributes\":{\"axis\":{\"id\":\"4122\"},\"dimension\":1,\"grid_line_color\":null,\"ticker\":null},\"id\":\"4124\",\"type\":\"Grid\"},{\"attributes\":{\"data\":{\"cotton\":[0,5900,1400,1600,0,0,22600,0,3300,2545,0,0,0,0,0,0,1200,0,7000,600,2600],\"countries\":[\"Argentina\",\"Australia\",\"Bangladesh\",\"Brazil\",\"Burundi\",\"Canada\",\"China\",\"Cote d'Ivoire\",\"Greece\",\"India\",\"Indonesia\",\"Italy\",\"Japan\",\"Korea\",\"Liberia\",\"Malaysia\",\"Thailand\",\"Turkey\",\"United States\",\"United states\",\"Uzbekistan\",\"Vietnam\"],\"leather\":[140,2740,0,480,680,125,1800,0,0,0,0,790,0,160,0,0,180,0,800,0,260],\"rubber\":[0,0,0,0,0,0,2400,1100,0,1690,2600,0,730,0,2300,2040,4840,0,1000,0,810]},\"selected\":{\"id\":\"4184\"},\"selection_policy\":{\"id\":\"4185\"}},\"id\":\"4106\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"end\":22600},\"id\":\"4110\",\"type\":\"Range1d\"},{\"attributes\":{},\"id\":\"4184\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"4119\",\"type\":\"BasicTicker\"},{\"attributes\":{\"range\":{\"id\":\"4112\"}},\"id\":\"4132\",\"type\":\"Dodge\"},{\"attributes\":{\"fill_color\":{\"value\":\"#e84d60\"},\"height\":{\"value\":0.2},\"line_color\":{\"value\":\"#e84d60\"},\"right\":{\"field\":\"leather\"},\"y\":{\"field\":\"countries\",\"transform\":{\"id\":\"4138\"}}},\"id\":\"4140\",\"type\":\"HBar\"},{\"attributes\":{\"source\":{\"id\":\"4106\"}},\"id\":\"4137\",\"type\":\"CDSView\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\"},\"id\":\"4125\",\"type\":\"Toolbar\"},{\"attributes\":{\"data_source\":{\"id\":\"4106\"},\"glyph\":{\"id\":\"4128\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"4129\"},\"selection_glyph\":null,\"view\":{\"id\":\"4131\"}},\"id\":\"4130\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"4114\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_color\":{\"value\":\"#c9d9d3\"},\"height\":{\"value\":0.2},\"line_color\":{\"value\":\"#c9d9d3\"},\"right\":{\"field\":\"cotton\"},\"y\":{\"field\":\"countries\",\"transform\":{\"id\":\"4126\"}}},\"id\":\"4128\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"4116\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"text\":\"Commodities bought by Country\"},\"id\":\"4108\",\"type\":\"Title\"}],\"root_ids\":[\"4107\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
" var render_items = [{\"docid\":\"75d1a69e-bc84-467f-baa0-3fea72f06b91\",\"root_ids\":[\"4107\"],\"roots\":{\"4107\":\"910eb92f-3407-4a8c-a787-758f7dca5ae6\"}}];\n",
" root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
"\n",
" }\n",
" if (root.Bokeh !== undefined) {\n",
" embed_document(root);\n",
" } else {\n",
" var attempts = 0;\n",
" var timer = setInterval(function(root) {\n",
" if (root.Bokeh !== undefined) {\n",
" clearInterval(timer);\n",
" embed_document(root);\n",
" } else {\n",
" attempts++;\n",
" if (attempts > 100) {\n",
" clearInterval(timer);\n",
" console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
" }\n",
" }\n",
" }, 10, root)\n",
" }\n",
"})(window);"
],
"application/vnd.bokehjs_exec.v0+json": ""
},
"metadata": {
"application/vnd.bokehjs_exec.v0+json": {
"id": "4107"
}
},
"output_type": "display_data"
}
],
"source": [
"#countries = list(set(sorted_.index.get_level_values(0)))\n",
"commodities = ['Cotton', 'Rubber', 'Leather']\n",
"\n",
"data = {\n",
" 'countries':['Argentina','Australia','Bangladesh','Brazil','Burundi','Canada','China',\"Cote d'Ivoire\",'Greece','India','Indonesia','Italy','Japan','Korea','Liberia','Malaysia','Thailand','Turkey','United States','United states','Uzbekistan','Vietnam'],\n",
" 'cotton':[0,5900,1400,1600, 0, 0,22600,0,3300,2545,0,0,0,0,0,0,1200,0,7000,600, 2600],\n",
" 'rubber':[0,0,0,0,0,0,2400,1100,0,1690,2600,0,730,0,2300,2040,4840,0,1000,0,810],\n",
" 'leather':[140,2740,0,480,680,125,1800,0,0,0,0,790,0,160,0,0,180,0,800,0,260]\n",
"}\n",
"\n",
"source = ColumnDataSource(data=data)\n",
"\n",
"p = figure(y_range=countries, x_range=(0, 22600), plot_width=400, title=\"Commodities bought by Country\",\n",
" toolbar_location=None, tools=\"\")\n",
"\n",
"p.hbar(y=dodge('countries', -0.25, range=p.y_range), right='cotton', height=0.2, source=source,\n",
" color=\"#c9d9d3\")\n",
"\n",
"p.hbar(y=dodge('countries', 0.0, range=p.y_range), right='rubber', height=0.2, source=source,\n",
" color=\"#718dbf\")\n",
"\n",
"p.hbar(y=dodge('countries', 0.25, range=p.y_range), right='leather', height=0.2, source=source,\n",
" color=\"#e84d60\")\n",
"\n",
"p.y_range.range_padding = 0.1\n",
"p.ygrid.grid_line_color = None\n",
"\n",
"show(p)"
]
},
{
"cell_type": "markdown",
"id": "aa75d196",
"metadata": {},
"source": [
"## by location type:"
]
},
{
"cell_type": "code",
"execution_count": 130,
"id": "e0cef1a5",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" <div class=\"bk-root\" id=\"896da327-6ba5-4cea-ad3b-0d99c54eb58e\" data-root-id=\"3521\"></div>\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"(function(root) {\n",
" function embed_document(root) {\n",
" \n",
" var docs_json = {\"0ca3857c-8f6a-4c06-9c4d-95aa17cbec8a\":{\"roots\":{\"references\":[{\"attributes\":{\"children\":[{\"id\":\"3520\"},{\"id\":\"3518\"}]},\"id\":\"3521\",\"type\":\"Column\"},{\"attributes\":{\"code\":\"\\n var labels = {0: 'Origin country', 1: 'Origin supplier facility (warehouse, silo, mill, etc.)', 2: 'Unknown'};\\n return labels[tick];\\n \"},\"id\":\"3484\",\"type\":\"FuncTickFormatter\"},{\"attributes\":{\"children\":[[{\"id\":\"3413\"},0,0],[{\"id\":\"3451\"},0,1]]},\"id\":\"3518\",\"type\":\"GridBox\"},{\"attributes\":{\"overlay\":{\"id\":\"3476\"}},\"id\":\"3472\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"3476\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"axis\":{\"id\":\"3462\"},\"ticker\":null},\"id\":\"3465\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"3412\"}},\"id\":\"3414\",\"type\":\"CDSView\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":{\"id\":\"3471\"},\"active_tap\":\"auto\",\"tools\":[{\"id\":\"3470\"},{\"id\":\"3471\"},{\"id\":\"3472\"},{\"id\":\"3473\"},{\"id\":\"3474\"},{\"id\":\"3475\"},{\"id\":\"3501\"}]},\"id\":\"3477\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"3473\",\"type\":\"SaveTool\"},{\"attributes\":{\"label\":{\"value\":\" Volume\"},\"renderers\":[{\"id\":\"3490\"}]},\"id\":\"3500\",\"type\":\"LegendItem\"},{\"attributes\":{\"editor\":{\"id\":\"3508\"},\"field\":\"location\",\"formatter\":{\"id\":\"3507\"},\"title\":\"location\"},\"id\":\"3410\",\"type\":\"TableColumn\"},{\"attributes\":{},\"id\":\"3506\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"source\":{\"id\":\"3450\"}},\"id\":\"3491\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"3470\",\"type\":\"PanTool\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"line_width\":{\"value\":2},\"top\":{\"field\":\"Volume\"},\"width\":{\"value\":0.7},\"x\":{\"field\":\"__x__values\",\"transform\":{\"id\":\"3486\"}}},\"id\":\"3488\",\"type\":\"VBar\"},{\"attributes\":{\"text\":\"Total volume purchased by Location type\"},\"id\":\"3452\",\"type\":\"Title\"},{\"attributes\":{\"callback\":null,\"mode\":\"vline\",\"renderers\":[{\"id\":\"3490\"}],\"tooltips\":[[\"Location t\",\"@__x__values_original\"],[\"Volume\",\"@{Volume}\"]]},\"id\":\"3501\",\"type\":\"HoverTool\"},{\"attributes\":{\"editor\":{\"id\":\"3510\"},\"field\":\"volume\",\"formatter\":{\"id\":\"3509\"},\"title\":\"volume\"},\"id\":\"3411\",\"type\":\"TableColumn\"},{\"attributes\":{\"below\":[{\"id\":\"3462\"}],\"center\":[{\"id\":\"3465\"},{\"id\":\"3469\"},{\"id\":\"3499\"}],\"left\":[{\"id\":\"3466\"}],\"output_backend\":\"webgl\",\"plot_height\":350,\"plot_width\":300,\"renderers\":[{\"id\":\"3490\"}],\"sizing_mode\":\"fixed\",\"title\":{\"id\":\"3452\"},\"toolbar\":{\"id\":\"3477\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"3454\"},\"x_scale\":{\"id\":\"3458\"},\"y_range\":{\"id\":\"3456\"},\"y_scale\":{\"id\":\"3460\"}},\"id\":\"3451\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"click_policy\":\"hide\",\"items\":[{\"id\":\"3500\"}]},\"id\":\"3499\",\"type\":\"Legend\"},{\"attributes\":{\"data_source\":{\"id\":\"3450\"},\"glyph\":{\"id\":\"3488\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"3489\"},\"selection_glyph\":null,\"view\":{\"id\":\"3491\"}},\"id\":\"3490\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"3494\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"data\":{\"Volume\":[19345,39110,17955],\"__x__values\":[0,1,2],\"__x__values_original\":[\"Origin country\",\"Origin supplier facility (warehouse, silo, mill, etc.)\",\"Unknown\"]},\"selected\":{\"id\":\"3496\"},\"selection_policy\":{\"id\":\"3497\"}},\"id\":\"3450\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"3456\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"3496\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"3458\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"3475\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"3508\",\"type\":\"StringEditor\"},{\"attributes\":{\"axis_label\":\"Volume\",\"formatter\":{\"id\":\"3494\"},\"ticker\":{\"id\":\"3467\"}},\"id\":\"3466\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"3474\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"3507\",\"type\":\"StringFormatter\"},{\"attributes\":{},\"id\":\"3467\",\"type\":\"BasicTicker\"},{\"attributes\":{\"columns\":[{\"id\":\"3410\"},{\"id\":\"3411\"}],\"height\":300,\"source\":{\"id\":\"3412\"},\"view\":{\"id\":\"3414\"}},\"id\":\"3413\",\"type\":\"DataTable\"},{\"attributes\":{\"toolbars\":[{\"id\":\"3477\"}],\"tools\":[{\"id\":\"3470\"},{\"id\":\"3471\"},{\"id\":\"3472\"},{\"id\":\"3473\"},{\"id\":\"3474\"},{\"id\":\"3475\"},{\"id\":\"3501\"}]},\"id\":\"3519\",\"type\":\"ProxyToolbar\"},{\"attributes\":{\"axis\":{\"id\":\"3466\"},\"dimension\":1,\"ticker\":null},\"id\":\"3469\",\"type\":\"Grid\"},{\"attributes\":{\"ticks\":[0,1,2]},\"id\":\"3503\",\"type\":\"FixedTicker\"},{\"attributes\":{\"axis_label\":\"Location t\",\"formatter\":{\"id\":\"3484\"},\"ticker\":{\"id\":\"3503\"}},\"id\":\"3462\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"3497\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"data\":{\"index\":[0,1,2],\"location\":[\"Origin country\",\"Origin supplier facility (warehouse, silo, mill, etc.)\",\"Unknown\"],\"volume\":[19345,39110,17955]},\"selected\":{\"id\":\"3505\"},\"selection_policy\":{\"id\":\"3506\"}},\"id\":\"3412\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"3505\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"3471\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"toolbar\":{\"id\":\"3519\"},\"toolbar_location\":\"above\"},\"id\":\"3520\",\"type\":\"ToolbarBox\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"line_width\":{\"value\":2},\"top\":{\"field\":\"Volume\"},\"width\":{\"value\":0.7},\"x\":{\"field\":\"__x__values\",\"transform\":{\"id\":\"3486\"}}},\"id\":\"3489\",\"type\":\"VBar\"},{\"attributes\":{\"range\":{\"id\":\"3454\"}},\"id\":\"3486\",\"type\":\"Dodge\"},{\"attributes\":{},\"id\":\"3509\",\"type\":\"StringFormatter\"},{\"attributes\":{},\"id\":\"3460\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"3454\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"3510\",\"type\":\"StringEditor\"}],\"root_ids\":[\"3521\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
" var render_items = [{\"docid\":\"0ca3857c-8f6a-4c06-9c4d-95aa17cbec8a\",\"root_ids\":[\"3521\"],\"roots\":{\"3521\":\"896da327-6ba5-4cea-ad3b-0d99c54eb58e\"}}];\n",
" root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
"\n",
" }\n",
" if (root.Bokeh !== undefined) {\n",
" embed_document(root);\n",
" } else {\n",
" var attempts = 0;\n",
" var timer = setInterval(function(root) {\n",
" if (root.Bokeh !== undefined) {\n",
" clearInterval(timer);\n",
" embed_document(root);\n",
" } else {\n",
" attempts++;\n",
" if (attempts > 100) {\n",
" clearInterval(timer);\n",
" console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
" }\n",
" }\n",
" }, 10, root)\n",
" }\n",
"})(window);"
],
"application/vnd.bokehjs_exec.v0+json": ""
},
"metadata": {
"application/vnd.bokehjs_exec.v0+json": {
"id": "3521"
}
},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div style=\"display: table;\"><div style=\"display: table-row;\"><div style=\"display: table-cell;\"><b title=\"bokeh.models.layouts.Column\">Column</b>(</div><div style=\"display: table-cell;\">id = '3521', <span id=\"3607\" style=\"cursor: pointer;\">…)</span></div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">align = 'start',</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">aspect_ratio = None,</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">background = None,</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">children = [ToolbarBox(id='3520', ...), GridBox(id='3518', ...)],</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">css_classes = [],</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">disabled = False,</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">height = None,</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">height_policy = 'auto',</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_event_callbacks = {},</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_property_callbacks = {},</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">margin = (0, 0, 0, 0),</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">max_height = None,</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">max_width = None,</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">min_height = None,</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">min_width = None,</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">name = None,</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">rows = 'auto',</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">sizing_mode = None,</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">spacing = 0,</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">subscribed_events = [],</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">tags = [],</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">visible = True,</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">width = None,</div></div><div class=\"3606\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">width_policy = 'auto')</div></div></div>\n",
"<script>\n",
"(function() {\n",
" var expanded = false;\n",
" var ellipsis = document.getElementById(\"3607\");\n",
" ellipsis.addEventListener(\"click\", function() {\n",
" var rows = document.getElementsByClassName(\"3606\");\n",
" for (var i = 0; i < rows.length; i++) {\n",
" var el = rows[i];\n",
" el.style.display = expanded ? \"none\" : \"table-row\";\n",
" }\n",
" ellipsis.innerHTML = expanded ? \"…)\" : \"‹‹‹\";\n",
" expanded = !expanded;\n",
" });\n",
"})();\n",
"</script>\n"
],
"text/plain": [
"Column(id='3521', ...)"
]
},
"execution_count": 130,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#group by materials\n",
"#group by material\n",
"risk_lt = mock_data.groupby('Location t').sum()\n",
"\n",
"## volume dataframe\n",
"lt = list(risk_lt.index)\n",
"volumens = list(risk_lt['Volume'])\n",
"df = gpd.GeoDataFrame()\n",
"df['location']=lt\n",
"df['volume']=volumens# Create Bokeh-Table with DataFrame:\n",
"\n",
"\n",
"data_table = DataTable(\n",
" columns=[TableColumn(field=Ci, title=Ci) for Ci in df.columns],\n",
" source=ColumnDataSource(df),\n",
" height=300,\n",
")\n",
"\n",
"p_bar = risk_material[['Volume']].plot_bokeh(\n",
" kind='bar',\n",
" title=\"Total volume purchased by Location type\",\n",
" show_figure=False,\n",
") \n",
"\n",
"#Combine Table and Scatterplot via grid layout:\n",
"pandas_bokeh.plot_grid([[data_table, p_bar]], plot_width=300, plot_height=350)"
]
},
{
"cell_type": "code",
"execution_count": 133,
"id": "a77aa5b6",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" <div class=\"bk-root\" id=\"990e5aef-3408-494e-b10b-e2ca5dffcb47\" data-root-id=\"3690\"></div>\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"(function(root) {\n",
" function embed_document(root) {\n",
" \n",
" var docs_json = {\"6a448c35-4e90-4826-856d-c1010783182c\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"3701\"}],\"center\":[{\"id\":\"3704\"},{\"id\":\"3708\"},{\"id\":\"3727\"}],\"left\":[{\"id\":\"3705\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"3718\"}],\"title\":{\"id\":\"3691\"},\"toolbar\":{\"id\":\"3710\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"3693\"},\"x_scale\":{\"id\":\"3697\"},\"y_range\":{\"id\":\"3695\"},\"y_scale\":{\"id\":\"3699\"}},\"id\":\"3690\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"end_angle\":{\"expr\":{\"id\":\"3713\"},\"units\":\"rad\"},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"color\"},\"inner_radius\":{\"units\":\"data\",\"value\":0.2},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"outer_radius\":{\"units\":\"data\",\"value\":0.4},\"start_angle\":{\"expr\":{\"id\":\"3712\"},\"units\":\"rad\"},\"x\":{\"value\":0},\"y\":{\"value\":1}},\"id\":\"3717\",\"type\":\"AnnularWedge\"},{\"attributes\":{\"items\":[{\"id\":\"3728\"}]},\"id\":\"3727\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"3724\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"3722\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"3699\",\"type\":\"LinearScale\"},{\"attributes\":{\"end_angle\":{\"expr\":{\"id\":\"3713\"},\"units\":\"rad\"},\"fill_color\":{\"field\":\"color\"},\"inner_radius\":{\"units\":\"data\",\"value\":0.2},\"line_color\":{\"value\":\"white\"},\"outer_radius\":{\"units\":\"data\",\"value\":0.4},\"start_angle\":{\"expr\":{\"id\":\"3712\"},\"units\":\"rad\"},\"x\":{\"value\":0},\"y\":{\"value\":1}},\"id\":\"3716\",\"type\":\"AnnularWedge\"},{\"attributes\":{},\"id\":\"3693\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"3697\",\"type\":\"LinearScale\"},{\"attributes\":{\"field\":\"angle\",\"include_zero\":true},\"id\":\"3712\",\"type\":\"CumSum\"},{\"attributes\":{\"axis_label\":null,\"formatter\":{\"id\":\"3722\"},\"ticker\":{\"id\":\"3706\"},\"visible\":false},\"id\":\"3705\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"3725\",\"type\":\"Selection\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"3709\"}]},\"id\":\"3710\",\"type\":\"Toolbar\"},{\"attributes\":{\"label\":{\"field\":\"Location\"},\"renderers\":[{\"id\":\"3718\"}]},\"id\":\"3728\",\"type\":\"LegendItem\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"Location\",\"@Location\"],[\"Value\",\"@value\"]]},\"id\":\"3709\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"3726\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"axis_label\":null,\"formatter\":{\"id\":\"3724\"},\"ticker\":{\"id\":\"3702\"},\"visible\":false},\"id\":\"3701\",\"type\":\"LinearAxis\"},{\"attributes\":{\"axis\":{\"id\":\"3701\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"3704\",\"type\":\"Grid\"},{\"attributes\":{\"data\":{\"Location\":[\"Origin country\",\"Origin supplier\",\"Unknown\"],\"angle\":{\"__ndarray__\":\"552it6hz+T9oUfzQY7oJQKhzdfd8n/c/\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[3]},\"color\":[\"#2ca25f\",\"#99d8c9\",\"#e5f5f9\"],\"index\":[\"0\",\"1\",\"2\"],\"value\":[19345,39110,17955]},\"selected\":{\"id\":\"3725\"},\"selection_policy\":{\"id\":\"3726\"}},\"id\":\"3714\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"text\":\"Purchased volume by location type (tonnes)\"},\"id\":\"3691\",\"type\":\"Title\"},{\"attributes\":{\"axis\":{\"id\":\"3705\"},\"dimension\":1,\"grid_line_color\":null,\"ticker\":null},\"id\":\"3708\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"3714\"}},\"id\":\"3719\",\"type\":\"CDSView\"},{\"attributes\":{\"field\":\"angle\"},\"id\":\"3713\",\"type\":\"CumSum\"},{\"attributes\":{},\"id\":\"3706\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"3702\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"3695\",\"type\":\"DataRange1d\"},{\"attributes\":{\"data_source\":{\"id\":\"3714\"},\"glyph\":{\"id\":\"3716\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"3717\"},\"selection_glyph\":null,\"view\":{\"id\":\"3719\"}},\"id\":\"3718\",\"type\":\"GlyphRenderer\"}],\"root_ids\":[\"3690\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
" var render_items = [{\"docid\":\"6a448c35-4e90-4826-856d-c1010783182c\",\"root_ids\":[\"3690\"],\"roots\":{\"3690\":\"990e5aef-3408-494e-b10b-e2ca5dffcb47\"}}];\n",
" root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
"\n",
" }\n",
" if (root.Bokeh !== undefined) {\n",
" embed_document(root);\n",
" } else {\n",
" var attempts = 0;\n",
" var timer = setInterval(function(root) {\n",
" if (root.Bokeh !== undefined) {\n",
" clearInterval(timer);\n",
" embed_document(root);\n",
" } else {\n",
" attempts++;\n",
" if (attempts > 100) {\n",
" clearInterval(timer);\n",
" console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
" }\n",
" }\n",
" }, 10, root)\n",
" }\n",
"})(window);"
],
"application/vnd.bokehjs_exec.v0+json": ""
},
"metadata": {
"application/vnd.bokehjs_exec.v0+json": {
"id": "3690"
}
},
"output_type": "display_data"
}
],
"source": [
"x = Counter({\n",
" 'Origin country': 19345, 'Origin supplier': 39110, 'Unknown': 17955\n",
"})\n",
"\n",
"data = pd.DataFrame.from_dict(dict(x), orient='index').reset_index().rename(index=str, columns={0:'value', 'index':'Location'})\n",
"data['angle'] = data['value']/sum(x.values()) * 2*pi\n",
"data['color'] = BuGn[len(x)]\n",
"\n",
"# Plotting code\n",
"\n",
"p = figure(plot_height=350, title=\"Purchased volume by location type (tonnes)\", toolbar_location=None,\n",
" tools=\"hover\", tooltips=[(\"Location\", \"@Location\"),(\"Value\", \"@value\")])\n",
"\n",
"p.annular_wedge(x=0, y=1, inner_radius=0.2, outer_radius=0.4,\n",
" start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'),\n",
" line_color=\"white\", fill_color='color', legend='Location', source=data)\n",
"\n",
"p.axis.axis_label=None\n",
"p.axis.visible=False\n",
"p.grid.grid_line_color = None\n",
"\n",
"show(p)"
]
},
{
"cell_type": "markdown",
"id": "14767af0",
"metadata": {},
"source": [
"## water impacts:"
]
},
{
"cell_type": "code",
"execution_count": 175,
"id": "daf45835",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Material</th>\n",
" <th>Volume</th>\n",
" <th>Country</th>\n",
" <th>Location t</th>\n",
" <th>Accuracy</th>\n",
" <th>wr_mean</th>\n",
" <th>wr_median</th>\n",
" <th>wr_std</th>\n",
" <th>wr_max</th>\n",
" <th>wr_min</th>\n",
" <th>geometry</th>\n",
" <th>wr_imp</th>\n",
" <th>wr_imp_min</th>\n",
" <th>wr_imp_max</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Rubber</td>\n",
" <td>2400</td>\n",
" <td>China</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>1.686943</td>\n",
" <td>1.375327e-01</td>\n",
" <td>3.525667</td>\n",
" <td>58.743172</td>\n",
" <td>1.000000e-15</td>\n",
" <td>MULTIPOLYGON (((73.49973 39.38174, 73.50468 39...</td>\n",
" <td>4048.663380</td>\n",
" <td>2.400000e-12</td>\n",
" <td>1.409836e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Rubber</td>\n",
" <td>1300</td>\n",
" <td>Malaysia</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>226.718707</td>\n",
" <td>7.263023e+01</td>\n",
" <td>320.896829</td>\n",
" <td>1948.873047</td>\n",
" <td>1.174634e-01</td>\n",
" <td>MULTIPOLYGON (((98.93721 5.68384, 98.93771 5.6...</td>\n",
" <td>294734.319486</td>\n",
" <td>1.527024e+02</td>\n",
" <td>2.533535e+06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Rubber</td>\n",
" <td>1000</td>\n",
" <td>United States</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>0.088295</td>\n",
" <td>1.533124e-09</td>\n",
" <td>0.287133</td>\n",
" <td>1.150512</td>\n",
" <td>1.087530e-10</td>\n",
" <td>MULTIPOLYGON (((-180.00000 51.79409, -180.0000...</td>\n",
" <td>88.295126</td>\n",
" <td>1.087530e-07</td>\n",
" <td>1.150512e+03</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Rubber</td>\n",
" <td>730</td>\n",
" <td>Japan</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>MULTIPOLYGON (((122.71418 24.44983, 122.71457 ...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Rubber</td>\n",
" <td>490</td>\n",
" <td>India</td>\n",
" <td>Unknown</td>\n",
" <td>Low</td>\n",
" <td>45.279566</td>\n",
" <td>4.625767e-01</td>\n",
" <td>181.590908</td>\n",
" <td>2934.395020</td>\n",
" <td>1.358522e-09</td>\n",
" <td>MULTIPOLYGON (((68.11138 23.60145, 68.13528 23...</td>\n",
" <td>22186.987158</td>\n",
" <td>6.656758e-07</td>\n",
" <td>1.437854e+06</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Material Volume Country Location t Accuracy wr_mean \\\n",
"0 Rubber 2400 China Unknown Low 1.686943 \n",
"1 Rubber 1300 Malaysia Unknown Low 226.718707 \n",
"2 Rubber 1000 United States Unknown Low 0.088295 \n",
"3 Rubber 730 Japan Unknown Low NaN \n",
"4 Rubber 490 India Unknown Low 45.279566 \n",
"\n",
" wr_median wr_std wr_max wr_min \\\n",
"0 1.375327e-01 3.525667 58.743172 1.000000e-15 \n",
"1 7.263023e+01 320.896829 1948.873047 1.174634e-01 \n",
"2 1.533124e-09 0.287133 1.150512 1.087530e-10 \n",
"3 NaN NaN NaN NaN \n",
"4 4.625767e-01 181.590908 2934.395020 1.358522e-09 \n",
"\n",
" geometry wr_imp \\\n",
"0 MULTIPOLYGON (((73.49973 39.38174, 73.50468 39... 4048.663380 \n",
"1 MULTIPOLYGON (((98.93721 5.68384, 98.93771 5.6... 294734.319486 \n",
"2 MULTIPOLYGON (((-180.00000 51.79409, -180.0000... 88.295126 \n",
"3 MULTIPOLYGON (((122.71418 24.44983, 122.71457 ... NaN \n",
"4 MULTIPOLYGON (((68.11138 23.60145, 68.13528 23... 22186.987158 \n",
"\n",
" wr_imp_min wr_imp_max \n",
"0 2.400000e-12 1.409836e+05 \n",
"1 1.527024e+02 2.533535e+06 \n",
"2 1.087530e-07 1.150512e+03 \n",
"3 NaN NaN \n",
"4 6.656758e-07 1.437854e+06 "
]
},
"execution_count": 175,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"water_risk_impact = mock_data[['Material', 'Volume', 'Country', 'Location t', 'Accuracy', 'wr_mean', 'wr_median', 'wr_std',\n",
" 'wr_max', 'wr_min', 'geometry',\n",
" 'wr_imp', 'wr_imp_min', 'wr_imp_max']]\n",
"water_risk_impact.head()"
]
},
{
"cell_type": "code",
"execution_count": 195,
"id": "320ff8fb",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Volume</th>\n",
" <th>wr_mean</th>\n",
" <th>wr_median</th>\n",
" <th>wr_std</th>\n",
" <th>wr_max</th>\n",
" <th>wr_min</th>\n",
" <th>wr_imp</th>\n",
" <th>wr_imp_min</th>\n",
" <th>wr_imp_max</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Material</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Cotton</th>\n",
" <td>48745</td>\n",
" <td>1559.834051</td>\n",
" <td>704.584181</td>\n",
" <td>3.873800e+03</td>\n",
" <td>9.975564e+04</td>\n",
" <td>201.863288</td>\n",
" <td>3.655594e+06</td>\n",
" <td>5.642475e+05</td>\n",
" <td>1.479121e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Leather</th>\n",
" <td>8155</td>\n",
" <td>767231.370025</td>\n",
" <td>240862.741302</td>\n",
" <td>1.607439e+06</td>\n",
" <td>2.558558e+07</td>\n",
" <td>40688.022647</td>\n",
" <td>7.877214e+08</td>\n",
" <td>2.766791e+07</td>\n",
" <td>2.466315e+10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Rubber</th>\n",
" <td>19510</td>\n",
" <td>1783.558232</td>\n",
" <td>935.331831</td>\n",
" <td>2.194707e+03</td>\n",
" <td>1.602977e+04</td>\n",
" <td>359.796898</td>\n",
" <td>2.190081e+06</td>\n",
" <td>2.782766e+05</td>\n",
" <td>2.065244e+07</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Volume wr_mean wr_median wr_std wr_max \\\n",
"Material \n",
"Cotton 48745 1559.834051 704.584181 3.873800e+03 9.975564e+04 \n",
"Leather 8155 767231.370025 240862.741302 1.607439e+06 2.558558e+07 \n",
"Rubber 19510 1783.558232 935.331831 2.194707e+03 1.602977e+04 \n",
"\n",
" wr_min wr_imp wr_imp_min wr_imp_max \n",
"Material \n",
"Cotton 201.863288 3.655594e+06 5.642475e+05 1.479121e+08 \n",
"Leather 40688.022647 7.877214e+08 2.766791e+07 2.466315e+10 \n",
"Rubber 359.796898 2.190081e+06 2.782766e+05 2.065244e+07 "
]
},
"execution_count": 195,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#water risk by material\n",
"water_risk_impact_material = water_risk_impact.groupby('Material').sum()\n",
"water_risk_impact_material\n"
]
},
{
"cell_type": "code",
"execution_count": 203,
"id": "3e7315a2",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Volume</th>\n",
" <th>wr_mean</th>\n",
" <th>wr_median</th>\n",
" <th>wr_std</th>\n",
" <th>wr_max</th>\n",
" <th>wr_min</th>\n",
" <th>wr_imp</th>\n",
" <th>wr_imp_min</th>\n",
" <th>wr_imp_max</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Material</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Cotton</th>\n",
" <td>48745</td>\n",
" <td>1559.834051</td>\n",
" <td>704.584181</td>\n",
" <td>3.873800e+03</td>\n",
" <td>9.975564e+04</td>\n",
" <td>201.863288</td>\n",
" <td>3.655594e+06</td>\n",
" <td>5.642475e+05</td>\n",
" <td>1.479121e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Rubber</th>\n",
" <td>19510</td>\n",
" <td>1783.558232</td>\n",
" <td>935.331831</td>\n",
" <td>2.194707e+03</td>\n",
" <td>1.602977e+04</td>\n",
" <td>359.796898</td>\n",
" <td>2.190081e+06</td>\n",
" <td>2.782766e+05</td>\n",
" <td>2.065244e+07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Leather</th>\n",
" <td>8155</td>\n",
" <td>767231.370025</td>\n",
" <td>240862.741302</td>\n",
" <td>1.607439e+06</td>\n",
" <td>2.558558e+07</td>\n",
" <td>40688.022647</td>\n",
" <td>7.877214e+08</td>\n",
" <td>2.766791e+07</td>\n",
" <td>2.466315e+10</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Volume wr_mean wr_median wr_std wr_max \\\n",
"Material \n",
"Cotton 48745 1559.834051 704.584181 3.873800e+03 9.975564e+04 \n",
"Rubber 19510 1783.558232 935.331831 2.194707e+03 1.602977e+04 \n",
"Leather 8155 767231.370025 240862.741302 1.607439e+06 2.558558e+07 \n",
"\n",
" wr_min wr_imp wr_imp_min wr_imp_max \n",
"Material \n",
"Cotton 201.863288 3.655594e+06 5.642475e+05 1.479121e+08 \n",
"Rubber 359.796898 2.190081e+06 2.782766e+05 2.065244e+07 \n",
"Leather 40688.022647 7.877214e+08 2.766791e+07 2.466315e+10 "
]
},
"execution_count": 203,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"water_risk_material = water_risk_impact_material.sort_values('wr_mean', ascending=True)\n",
"water_risk_material"
]
},
{
"cell_type": "code",
"execution_count": 204,
"id": "0d42dd5c",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Volume</th>\n",
" <th>wr_mean</th>\n",
" <th>wr_median</th>\n",
" <th>wr_std</th>\n",
" <th>wr_max</th>\n",
" <th>wr_min</th>\n",
" <th>wr_imp</th>\n",
" <th>wr_imp_min</th>\n",
" <th>wr_imp_max</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Material</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Rubber</th>\n",
" <td>19510</td>\n",
" <td>1783.558232</td>\n",
" <td>935.331831</td>\n",
" <td>2.194707e+03</td>\n",
" <td>1.602977e+04</td>\n",
" <td>359.796898</td>\n",
" <td>2.190081e+06</td>\n",
" <td>2.782766e+05</td>\n",
" <td>2.065244e+07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Cotton</th>\n",
" <td>48745</td>\n",
" <td>1559.834051</td>\n",
" <td>704.584181</td>\n",
" <td>3.873800e+03</td>\n",
" <td>9.975564e+04</td>\n",
" <td>201.863288</td>\n",
" <td>3.655594e+06</td>\n",
" <td>5.642475e+05</td>\n",
" <td>1.479121e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Leather</th>\n",
" <td>8155</td>\n",
" <td>767231.370025</td>\n",
" <td>240862.741302</td>\n",
" <td>1.607439e+06</td>\n",
" <td>2.558558e+07</td>\n",
" <td>40688.022647</td>\n",
" <td>7.877214e+08</td>\n",
" <td>2.766791e+07</td>\n",
" <td>2.466315e+10</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Volume wr_mean wr_median wr_std wr_max \\\n",
"Material \n",
"Rubber 19510 1783.558232 935.331831 2.194707e+03 1.602977e+04 \n",
"Cotton 48745 1559.834051 704.584181 3.873800e+03 9.975564e+04 \n",
"Leather 8155 767231.370025 240862.741302 1.607439e+06 2.558558e+07 \n",
"\n",
" wr_min wr_imp wr_imp_min wr_imp_max \n",
"Material \n",
"Rubber 359.796898 2.190081e+06 2.782766e+05 2.065244e+07 \n",
"Cotton 201.863288 3.655594e+06 5.642475e+05 1.479121e+08 \n",
"Leather 40688.022647 7.877214e+08 2.766791e+07 2.466315e+10 "
]
},
"execution_count": 204,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"water_impact_material = water_risk_impact_material.sort_values('wr_imp', ascending=True)\n",
"water_impact_material"
]
},
{
"cell_type": "code",
"execution_count": 205,
"id": "a0e6c0ec",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
"BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" <div class=\"bk-root\" id=\"2b181527-e597-4ad6-bbbc-423f784cc533\" data-root-id=\"6709\"></div>\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"(function(root) {\n",
" function embed_document(root) {\n",
" \n",
" var docs_json = {\"1044bfd9-3a89-4d9b-b3f7-aa864fb8def3\":{\"roots\":{\"references\":[{\"attributes\":{\"children\":[{\"id\":\"6708\"},{\"id\":\"6706\"}]},\"id\":\"6709\",\"type\":\"Column\"},{\"attributes\":{\"axis\":{\"id\":\"6595\"},\"ticker\":null},\"id\":\"6598\",\"type\":\"Grid\"},{\"attributes\":{\"label\":{\"field\":\"Commodity\"},\"renderers\":[{\"id\":\"6572\"}]},\"id\":\"6582\",\"type\":\"LegendItem\"},{\"attributes\":{\"data_source\":{\"id\":\"6583\"},\"glyph\":{\"id\":\"6605\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"6606\"},\"selection_glyph\":null,\"view\":{\"id\":\"6608\"}},\"id\":\"6607\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis_label\":null,\"formatter\":{\"id\":\"6578\"},\"ticker\":{\"id\":\"6556\"},\"visible\":false},\"id\":\"6555\",\"type\":\"LinearAxis\"},{\"attributes\":{\"source\":{\"id\":\"6568\"}},\"id\":\"6573\",\"type\":\"CDSView\"},{\"attributes\":{\"end_angle\":{\"expr\":{\"id\":\"6567\"},\"units\":\"rad\"},\"fill_color\":{\"field\":\"color\"},\"inner_radius\":{\"units\":\"data\",\"value\":0.2},\"line_color\":{\"value\":\"white\"},\"outer_radius\":{\"units\":\"data\",\"value\":0.4},\"start_angle\":{\"expr\":{\"id\":\"6566\"},\"units\":\"rad\"},\"x\":{\"value\":0},\"y\":{\"value\":1}},\"id\":\"6570\",\"type\":\"AnnularWedge\"},{\"attributes\":{},\"id\":\"6661\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"6547\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis\":{\"id\":\"6664\"},\"dimension\":1,\"grid_line_color\":null,\"ticker\":null},\"id\":\"6666\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"6593\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"fill_color\":{\"value\":\"#c9d9d3\"},\"height\":{\"value\":0.2},\"line_color\":{\"value\":\"#c9d9d3\"},\"right\":{\"field\":\"risk\"},\"y\":{\"field\":\"material\",\"transform\":{\"id\":\"6603\"}}},\"id\":\"6605\",\"type\":\"HBar\"},{\"attributes\":{\"data\":{\"impact\":[1783.5582316980867,1559.8340505531007,767231.3700254008],\"material\":[\"Rubber\",\"Cotton\",\"Leather\"]},\"selected\":{\"id\":\"6703\"},\"selection_policy\":{\"id\":\"6704\"}},\"id\":\"6648\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"text\":\"Top commodities by water risk (m3/Tonnes)\"},\"id\":\"6585\",\"type\":\"Title\"},{\"attributes\":{\"axis_label\":null,\"formatter\":{\"id\":\"6576\"},\"ticker\":{\"id\":\"6560\"},\"visible\":false},\"id\":\"6559\",\"type\":\"LinearAxis\"},{\"attributes\":{\"label\":{\"field\":\"Commodity\"},\"renderers\":[{\"id\":\"6637\"}]},\"id\":\"6647\",\"type\":\"LegendItem\"},{\"attributes\":{\"below\":[{\"id\":\"6620\"}],\"center\":[{\"id\":\"6623\"},{\"id\":\"6627\"},{\"id\":\"6646\"}],\"left\":[{\"id\":\"6624\"}],\"plot_height\":350,\"plot_width\":450,\"renderers\":[{\"id\":\"6637\"}],\"title\":{\"id\":\"6610\"},\"toolbar\":{\"id\":\"6629\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"6612\"},\"x_scale\":{\"id\":\"6616\"},\"y_range\":{\"id\":\"6614\"},\"y_scale\":{\"id\":\"6618\"}},\"id\":\"6609\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"6556\",\"type\":\"BasicTicker\"},{\"attributes\":{\"data\":{\"Commodity\":[\"Cotton\",\"Leather\",\"Rubber\"],\"angle\":{\"__ndarray__\":\"RFe7bmujnT/PKopBlvIYQFbxRkunwZE/\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[3]},\"color\":[\"#2ca25f\",\"#99d8c9\",\"#e5f5f9\"],\"index\":[\"0\",\"1\",\"2\"],\"value\":{\"__ndarray__\":\"AAAAANXjS0EAAABc1nnHQQAAAICAtUBB\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[3]}},\"selected\":{\"id\":\"6644\"},\"selection_policy\":{\"id\":\"6645\"}},\"id\":\"6633\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"6591\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"6618\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"6576\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"6616\",\"type\":\"LinearScale\"},{\"attributes\":{\"range\":{\"id\":\"6482\"}},\"id\":\"6668\",\"type\":\"Dodge\"},{\"attributes\":{\"axis\":{\"id\":\"6599\"},\"dimension\":1,\"grid_line_color\":null,\"ticker\":null},\"id\":\"6601\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"6614\",\"type\":\"DataRange1d\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\"},\"id\":\"6602\",\"type\":\"Toolbar\"},{\"attributes\":{\"axis\":{\"id\":\"6555\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"6558\",\"type\":\"Grid\"},{\"attributes\":{\"fill_color\":{\"value\":\"#c9d9d3\"},\"height\":{\"value\":0.2},\"line_color\":{\"value\":\"#c9d9d3\"},\"right\":{\"field\":\"impact\"},\"y\":{\"field\":\"material\",\"transform\":{\"id\":\"6668\"}}},\"id\":\"6670\",\"type\":\"HBar\"},{\"attributes\":{\"data\":{\"Commodity\":[\"Cotton\",\"Leather\",\"Rubber\"],\"angle\":{\"__ndarray__\":\"vdmbAUYMij9oxbPYEAYZQH+HMx+xyI0/\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[3]},\"color\":[\"#2ca25f\",\"#99d8c9\",\"#e5f5f9\"],\"index\":[\"0\",\"1\",\"2\"],\"value\":{\"__ndarray__\":\"ySB3EVZfmECz6nO9/mknQVNeK6E73ptA\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[3]}},\"selected\":{\"id\":\"6579\"},\"selection_policy\":{\"id\":\"6580\"}},\"id\":\"6568\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"6563\"}]},\"id\":\"6564\",\"type\":\"Toolbar\"},{\"attributes\":{\"items\":[{\"id\":\"6582\"}]},\"id\":\"6581\",\"type\":\"Legend\"},{\"attributes\":{\"formatter\":{\"id\":\"6702\"},\"ticker\":{\"id\":\"6661\"}},\"id\":\"6660\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"6579\",\"type\":\"Selection\"},{\"attributes\":{\"end_angle\":{\"expr\":{\"id\":\"6632\"},\"units\":\"rad\"},\"fill_color\":{\"field\":\"color\"},\"inner_radius\":{\"units\":\"data\",\"value\":0.2},\"line_color\":{\"value\":\"white\"},\"outer_radius\":{\"units\":\"data\",\"value\":0.4},\"start_angle\":{\"expr\":{\"id\":\"6631\"},\"units\":\"rad\"},\"x\":{\"value\":0},\"y\":{\"value\":1}},\"id\":\"6635\",\"type\":\"AnnularWedge\"},{\"attributes\":{\"source\":{\"id\":\"6583\"}},\"id\":\"6608\",\"type\":\"CDSView\"},{\"attributes\":{\"axis_label\":null,\"formatter\":{\"id\":\"6643\"},\"ticker\":{\"id\":\"6621\"},\"visible\":false},\"id\":\"6620\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"6625\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"6559\"},\"dimension\":1,\"grid_line_color\":null,\"ticker\":null},\"id\":\"6562\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"6694\"},\"ticker\":{\"id\":\"6596\"}},\"id\":\"6595\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"6600\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"6596\",\"type\":\"BasicTicker\"},{\"attributes\":{\"end_angle\":{\"expr\":{\"id\":\"6567\"},\"units\":\"rad\"},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"color\"},\"inner_radius\":{\"units\":\"data\",\"value\":0.2},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"outer_radius\":{\"units\":\"data\",\"value\":0.4},\"start_angle\":{\"expr\":{\"id\":\"6566\"},\"units\":\"rad\"},\"x\":{\"value\":0},\"y\":{\"value\":1}},\"id\":\"6571\",\"type\":\"AnnularWedge\"},{\"attributes\":{\"factors\":[\"Rubber\",\"Cotton\",\"Leather\"],\"range_padding\":0.1},\"id\":\"6654\",\"type\":\"FactorRange\"},{\"attributes\":{\"text\":\"Unsustainable water use risk (m3/tonne) by commodity in 2000\"},\"id\":\"6545\",\"type\":\"Title\"},{\"attributes\":{\"end\":2067231.370025},\"id\":\"6587\",\"type\":\"Range1d\"},{\"attributes\":{},\"id\":\"6551\",\"type\":\"LinearScale\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\"},\"id\":\"6667\",\"type\":\"Toolbar\"},{\"attributes\":{\"data\":{\"material\":[\"Cotton\",\"Rubber\",\"Leather\"],\"risk\":[1559.8340505531007,1783.5582316980867,767231.3700254008]},\"selected\":{\"id\":\"6695\"},\"selection_policy\":{\"id\":\"6696\"}},\"id\":\"6583\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"formatter\":{\"id\":\"6692\"},\"ticker\":{\"id\":\"6600\"}},\"id\":\"6599\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"factors\":[\"Cotton\",\"Rubber\",\"Leather\"],\"range_padding\":0.1},\"id\":\"6589\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"6560\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"6665\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"children\":[[{\"id\":\"6544\"},0,0],[{\"id\":\"6609\"},0,1],[{\"id\":\"6584\"},1,0],[{\"id\":\"6649\"},1,1]]},\"id\":\"6706\",\"type\":\"GridBox\"},{\"attributes\":{},\"id\":\"6553\",\"type\":\"LinearScale\"},{\"attributes\":{\"range\":{\"id\":\"6482\"}},\"id\":\"6603\",\"type\":\"Dodge\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"Commodity\",\"@Commodity\"],[\"Value\",\"@value\"]]},\"id\":\"6563\",\"type\":\"HoverTool\"},{\"attributes\":{\"axis\":{\"id\":\"6660\"},\"ticker\":null},\"id\":\"6663\",\"type\":\"Grid\"},{\"attributes\":{\"below\":[{\"id\":\"6555\"}],\"center\":[{\"id\":\"6558\"},{\"id\":\"6562\"},{\"id\":\"6581\"}],\"left\":[{\"id\":\"6559\"}],\"plot_height\":350,\"plot_width\":450,\"renderers\":[{\"id\":\"6572\"}],\"title\":{\"id\":\"6545\"},\"toolbar\":{\"id\":\"6564\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"6547\"},\"x_scale\":{\"id\":\"6551\"},\"y_range\":{\"id\":\"6549\"},\"y_scale\":{\"id\":\"6553\"}},\"id\":\"6544\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"field\":\"angle\",\"include_zero\":true},\"id\":\"6631\",\"type\":\"CumSum\"},{\"attributes\":{\"end\":2067231.370025},\"id\":\"6652\",\"type\":\"Range1d\"},{\"attributes\":{\"axis\":{\"id\":\"6620\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"6623\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"6580\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"text\":\"Unsustainable water use impact (m3) by commodity in 2000\"},\"id\":\"6610\",\"type\":\"Title\"},{\"attributes\":{\"toolbars\":[{\"id\":\"6564\"},{\"id\":\"6629\"},{\"id\":\"6602\"},{\"id\":\"6667\"}],\"tools\":[{\"id\":\"6563\"},{\"id\":\"6628\"}]},\"id\":\"6707\",\"type\":\"ProxyToolbar\"},{\"attributes\":{\"axis\":{\"id\":\"6624\"},\"dimension\":1,\"grid_line_color\":null,\"ticker\":null},\"id\":\"6627\",\"type\":\"Grid\"},{\"attributes\":{\"data_source\":{\"id\":\"6568\"},\"glyph\":{\"id\":\"6570\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"6571\"},\"selection_glyph\":null,\"view\":{\"id\":\"6573\"}},\"id\":\"6572\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"formatter\":{\"id\":\"6700\"},\"ticker\":{\"id\":\"6665\"}},\"id\":\"6664\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"6656\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"6549\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"6621\",\"type\":\"BasicTicker\"},{\"attributes\":{\"text\":\"Top commodities by water impact (m3)\"},\"id\":\"6650\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"6578\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"6658\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"axis_label\":null,\"formatter\":{\"id\":\"6641\"},\"ticker\":{\"id\":\"6625\"},\"visible\":false},\"id\":\"6624\",\"type\":\"LinearAxis\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"Commodity\",\"@Commodity\"],[\"Value\",\"@value\"]]},\"id\":\"6628\",\"type\":\"HoverTool\"},{\"attributes\":{\"field\":\"angle\"},\"id\":\"6632\",\"type\":\"CumSum\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"6628\"}]},\"id\":\"6629\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#c9d9d3\"},\"height\":{\"value\":0.2},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#c9d9d3\"},\"right\":{\"field\":\"risk\"},\"y\":{\"field\":\"material\",\"transform\":{\"id\":\"6603\"}}},\"id\":\"6606\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"6612\",\"type\":\"DataRange1d\"},{\"attributes\":{\"below\":[{\"id\":\"6595\"}],\"center\":[{\"id\":\"6598\"},{\"id\":\"6601\"}],\"left\":[{\"id\":\"6599\"}],\"plot_width\":450,\"renderers\":[{\"id\":\"6607\"}],\"title\":{\"id\":\"6585\"},\"toolbar\":{\"id\":\"6602\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"6587\"},\"x_scale\":{\"id\":\"6591\"},\"y_range\":{\"id\":\"6589\"},\"y_scale\":{\"id\":\"6593\"}},\"id\":\"6584\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"toolbar\":{\"id\":\"6707\"},\"toolbar_location\":\"above\"},\"id\":\"6708\",\"type\":\"ToolbarBox\"},{\"attributes\":{\"data_source\":{\"id\":\"6633\"},\"glyph\":{\"id\":\"6635\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"6636\"},\"selection_glyph\":null,\"view\":{\"id\":\"6638\"}},\"id\":\"6637\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"field\":\"angle\",\"include_zero\":true},\"id\":\"6566\",\"type\":\"CumSum\"},{\"attributes\":{},\"id\":\"6645\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"field\":\"angle\"},\"id\":\"6567\",\"type\":\"CumSum\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#c9d9d3\"},\"height\":{\"value\":0.2},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#c9d9d3\"},\"right\":{\"field\":\"impact\"},\"y\":{\"field\":\"material\",\"transform\":{\"id\":\"6668\"}}},\"id\":\"6671\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"6700\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"items\":[{\"id\":\"6647\"}]},\"id\":\"6646\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"6644\",\"type\":\"Selection\"},{\"attributes\":{\"below\":[{\"id\":\"6660\"}],\"center\":[{\"id\":\"6663\"},{\"id\":\"6666\"}],\"left\":[{\"id\":\"6664\"}],\"plot_width\":450,\"renderers\":[{\"id\":\"6672\"}],\"title\":{\"id\":\"6650\"},\"toolbar\":{\"id\":\"6667\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"6652\"},\"x_scale\":{\"id\":\"6656\"},\"y_range\":{\"id\":\"6654\"},\"y_scale\":{\"id\":\"6658\"}},\"id\":\"6649\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"6692\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"end_angle\":{\"expr\":{\"id\":\"6632\"},\"units\":\"rad\"},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"color\"},\"inner_radius\":{\"units\":\"data\",\"value\":0.2},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"outer_radius\":{\"units\":\"data\",\"value\":0.4},\"start_angle\":{\"expr\":{\"id\":\"6631\"},\"units\":\"rad\"},\"x\":{\"value\":0},\"y\":{\"value\":1}},\"id\":\"6636\",\"type\":\"AnnularWedge\"},{\"attributes\":{},\"id\":\"6641\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"6648\"}},\"id\":\"6673\",\"type\":\"CDSView\"},{\"attributes\":{\"source\":{\"id\":\"6633\"}},\"id\":\"6638\",\"type\":\"CDSView\"},{\"attributes\":{\"data_source\":{\"id\":\"6648\"},\"glyph\":{\"id\":\"6670\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"6671\"},\"selection_glyph\":null,\"view\":{\"id\":\"6673\"}},\"id\":\"6672\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"6702\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"6694\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"factors\":[\"Cotton\",\"Rubber\",\"Leather\"],\"range_padding\":0.1},\"id\":\"6482\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"6695\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"6704\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"6696\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"6703\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"6643\",\"type\":\"BasicTickFormatter\"}],\"root_ids\":[\"6709\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
" var render_items = [{\"docid\":\"1044bfd9-3a89-4d9b-b3f7-aa864fb8def3\",\"root_ids\":[\"6709\"],\"roots\":{\"6709\":\"2b181527-e597-4ad6-bbbc-423f784cc533\"}}];\n",
" root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
"\n",
" }\n",
" if (root.Bokeh !== undefined) {\n",
" embed_document(root);\n",
" } else {\n",
" var attempts = 0;\n",
" var timer = setInterval(function(root) {\n",
" if (root.Bokeh !== undefined) {\n",
" clearInterval(timer);\n",
" embed_document(root);\n",
" } else {\n",
" attempts++;\n",
" if (attempts > 100) {\n",
" clearInterval(timer);\n",
" console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
" }\n",
" }\n",
" }, 10, root)\n",
" }\n",
"})(window);"
],
"application/vnd.bokehjs_exec.v0+json": ""
},
"metadata": {
"application/vnd.bokehjs_exec.v0+json": {
"id": "6709"
}
},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div style=\"display: table;\"><div style=\"display: table-row;\"><div style=\"display: table-cell;\"><b title=\"bokeh.models.layouts.Column\">Column</b>(</div><div style=\"display: table-cell;\">id = '6709', <span id=\"6886\" style=\"cursor: pointer;\">…)</span></div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">align = 'start',</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">aspect_ratio = None,</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">background = None,</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">children = [ToolbarBox(id='6708', ...), GridBox(id='6706', ...)],</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">css_classes = [],</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">disabled = False,</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">height = None,</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">height_policy = 'auto',</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_event_callbacks = {},</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_property_callbacks = {},</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">margin = (0, 0, 0, 0),</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">max_height = None,</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">max_width = None,</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">min_height = None,</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">min_width = None,</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">name = None,</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">rows = 'auto',</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">sizing_mode = None,</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">spacing = 0,</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">subscribed_events = [],</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">tags = [],</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">visible = True,</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">width = None,</div></div><div class=\"6885\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">width_policy = 'auto')</div></div></div>\n",
"<script>\n",
"(function() {\n",
" var expanded = false;\n",
" var ellipsis = document.getElementById(\"6886\");\n",
" ellipsis.addEventListener(\"click\", function() {\n",
" var rows = document.getElementsByClassName(\"6885\");\n",
" for (var i = 0; i < rows.length; i++) {\n",
" var el = rows[i];\n",
" el.style.display = expanded ? \"none\" : \"table-row\";\n",
" }\n",
" ellipsis.innerHTML = expanded ? \"…)\" : \"‹‹‹\";\n",
" expanded = !expanded;\n",
" });\n",
"})();\n",
"</script>\n"
],
"text/plain": [
"Column(id='6709', ...)"
]
},
"execution_count": 205,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"\n",
"#water risk as donnut chart\n",
"x = Counter({\n",
" 'Cotton': 1559.834051, 'Leather': 767231.370025, 'Rubber': 1783.558232\n",
"})\n",
"\n",
"data = pd.DataFrame.from_dict(dict(x), orient='index').reset_index().rename(index=str, columns={0:'value', 'index':'Commodity'})\n",
"data['angle'] = data['value']/sum(x.values()) * 2*pi\n",
"data['color'] = BuGn[len(x)]\n",
"\n",
"p_d_risk = figure(plot_height=350, title=\"Unsustainable water use risk (m3/tonne) by commodity in 2000\", toolbar_location=None,\n",
" tools=\"hover\", tooltips=[(\"Commodity\", \"@Commodity\"),(\"Value\", \"@value\")])\n",
"\n",
"p_d_risk.annular_wedge(x=0, y=1, inner_radius=0.2, outer_radius=0.4,\n",
" start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'),\n",
" line_color=\"white\", fill_color='color', legend='Commodity', source=data)\n",
"\n",
"p_d_risk.axis.axis_label=None\n",
"p_d_risk.axis.visible=False\n",
"p_d_risk.grid.grid_line_color = None\n",
"\n",
"#water risk as bar chart\n",
"\n",
"material = list(water_risk_material.index)\n",
"risk = list(water_risk_material['wr_mean'])\n",
"\n",
"\n",
"data = {'material': material,\n",
" 'risk': risk}\n",
"\n",
"source = ColumnDataSource(data)\n",
"\n",
"p_b_risk = figure(y_range=material, x_range=(0, 2067231.370025), plot_width=250, title=\"Top commodities by water risk (m3/Tonnes)\",\n",
" toolbar_location=None, tools=\"\")\n",
"\n",
"p_b_risk.hbar(y=dodge('material', 0, range=p.y_range), right='risk', height=0.2, source=source,\n",
" color=\"#c9d9d3\")\n",
"\n",
"p_b_risk.y_range.range_padding = 0.1\n",
"p_b_risk.ygrid.grid_line_color = None\n",
"\n",
"\n",
"\n",
"#water impact as donut chart\n",
"x = Counter({\n",
" 'Cotton': 3.655594e+06, 'Leather': 7.877214e+08, 'Rubber': 2.190081e+06\n",
"})\n",
"\n",
"data = pd.DataFrame.from_dict(dict(x), orient='index').reset_index().rename(index=str, columns={0:'value', 'index':'Commodity'})\n",
"data['angle'] = data['value']/sum(x.values()) * 2*pi\n",
"data['color'] = BuGn[len(x)]\n",
"\n",
"p_d_imp = figure(plot_height=350, title=\"Unsustainable water use impact (m3) by commodity in 2000\", toolbar_location=None,\n",
" tools=\"hover\", tooltips=[(\"Commodity\", \"@Commodity\"),(\"Value\", \"@value\")])\n",
"\n",
"p_d_imp.annular_wedge(x=0, y=1, inner_radius=0.2, outer_radius=0.4,\n",
" start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'),\n",
" line_color=\"white\", fill_color='color', legend='Commodity', source=data)\n",
"\n",
"p_d_imp.axis.axis_label=None\n",
"p_d_imp.axis.visible=False\n",
"p_d_imp.grid.grid_line_color = None\n",
"\n",
"#water impact as bar chart\n",
"\n",
"material = list(water_impact_material.index)\n",
"impact = list(water_impact_material['wr_mean'])\n",
"\n",
"\n",
"data = {'material': material,\n",
" 'impact': impact}\n",
"\n",
"source = ColumnDataSource(data)\n",
"\n",
"p_b_impact = figure(y_range=material, x_range=(0, 2067231.370025), plot_width=250, title=\"Top commodities by water impact (m3)\",\n",
" toolbar_location=None, tools=\"\")\n",
"\n",
"p_b_impact.hbar(y=dodge('material', 0, range=p.y_range), right='impact', height=0.2, source=source,\n",
" color=\"#c9d9d3\")\n",
"\n",
"p_b_impact.y_range.range_padding = 0.1\n",
"p_b_impact.ygrid.grid_line_color = None\n",
"\n",
"\n",
"#Make Dashboard with Grid Layout:\n",
"pandas_bokeh.plot_grid([[p_d_risk, p_d_imp],[p_b_risk,p_b_impact]], plot_width=450)"
]
},
{
"cell_type": "code",
"execution_count": 206,
"id": "43785002",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Unnamed: 0</th>\n",
" <th>2000</th>\n",
" <th>2001</th>\n",
" <th>2002</th>\n",
" <th>2003</th>\n",
" <th>2004</th>\n",
" <th>2005</th>\n",
" <th>2006</th>\n",
" <th>2007</th>\n",
" <th>2008</th>\n",
" <th>...</th>\n",
" <th>2011</th>\n",
" <th>2012</th>\n",
" <th>2013</th>\n",
" <th>2014</th>\n",
" <th>2015</th>\n",
" <th>2016</th>\n",
" <th>2017</th>\n",
" <th>2018</th>\n",
" <th>2019</th>\n",
" <th>country</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>NaN</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-0.400000</td>\n",
" <td>-0.15000</td>\n",
" <td>0.176471</td>\n",
" <td>0.065000</td>\n",
" <td>0.095462</td>\n",
" <td>0.000000</td>\n",
" <td>...</td>\n",
" <td>0.000</td>\n",
" <td>0.000000</td>\n",
" <td>0.10</td>\n",
" <td>-0.035813</td>\n",
" <td>0.203543</td>\n",
" <td>0.213133</td>\n",
" <td>-0.376835</td>\n",
" <td>0.240257</td>\n",
" <td>0.250025</td>\n",
" <td>Afghanistan</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1</td>\n",
" <td>NaN</td>\n",
" <td>-0.151515</td>\n",
" <td>0.000000</td>\n",
" <td>0.190476</td>\n",
" <td>0.06000</td>\n",
" <td>0.018868</td>\n",
" <td>0.000000</td>\n",
" <td>-0.120370</td>\n",
" <td>-0.221053</td>\n",
" <td>...</td>\n",
" <td>0.000</td>\n",
" <td>0.000000</td>\n",
" <td>0.00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-0.166216</td>\n",
" <td>Albania</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2</td>\n",
" <td>NaN</td>\n",
" <td>0.014184</td>\n",
" <td>0.020979</td>\n",
" <td>0.034247</td>\n",
" <td>0.02649</td>\n",
" <td>-0.470968</td>\n",
" <td>0.292683</td>\n",
" <td>0.169811</td>\n",
" <td>0.153226</td>\n",
" <td>...</td>\n",
" <td>0.055</td>\n",
" <td>0.184834</td>\n",
" <td>0.04</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.057692</td>\n",
" <td>Algeria</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>3</td>\n",
" <td>NaN</td>\n",
" <td>-0.800000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.00000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>...</td>\n",
" <td>0.500</td>\n",
" <td>0.000000</td>\n",
" <td>0.00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-0.018333</td>\n",
" <td>Angola</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>4</td>\n",
" <td>NaN</td>\n",
" <td>0.000000</td>\n",
" <td>0.083333</td>\n",
" <td>0.076923</td>\n",
" <td>0.00000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>...</td>\n",
" <td>0.000</td>\n",
" <td>-0.142857</td>\n",
" <td>0.00</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>-0.001667</td>\n",
" <td>Antigua and Barbuda</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 22 columns</p>\n",
"</div>"
],
"text/plain": [
" Unnamed: 0 2000 2001 2002 2003 2004 2005 \\\n",
"0 0 NaN 0.000000 0.000000 -0.400000 -0.15000 0.176471 \n",
"1 1 NaN -0.151515 0.000000 0.190476 0.06000 0.018868 \n",
"2 2 NaN 0.014184 0.020979 0.034247 0.02649 -0.470968 \n",
"3 3 NaN -0.800000 0.000000 0.000000 0.00000 0.000000 \n",
"4 4 NaN 0.000000 0.083333 0.076923 0.00000 0.000000 \n",
"\n",
" 2006 2007 2008 ... 2011 2012 2013 2014 \\\n",
"0 0.065000 0.095462 0.000000 ... 0.000 0.000000 0.10 -0.035813 \n",
"1 0.000000 -0.120370 -0.221053 ... 0.000 0.000000 0.00 0.000000 \n",
"2 0.292683 0.169811 0.153226 ... 0.055 0.184834 0.04 0.000000 \n",
"3 0.000000 0.000000 0.000000 ... 0.500 0.000000 0.00 0.000000 \n",
"4 0.000000 0.000000 0.000000 ... 0.000 -0.142857 0.00 0.000000 \n",
"\n",
" 2015 2016 2017 2018 2019 country \n",
"0 0.203543 0.213133 -0.376835 0.240257 0.250025 Afghanistan \n",
"1 0.000000 0.000000 0.000000 0.000000 -0.166216 Albania \n",
"2 0.000000 0.000000 0.000000 0.000000 0.057692 Algeria \n",
"3 0.000000 0.000000 0.000000 0.000000 -0.018333 Angola \n",
"4 0.000000 0.000000 0.000000 0.000000 -0.001667 Antigua and Barbuda \n",
"\n",
"[5 rows x 22 columns]"
]
},
"execution_count": 206,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#risk and impact over time\n",
"pct_change_df = pd.read_csv('../../datasets/raw/crop_data/projection_factor_byCountry.csv')\n",
"pct_change_df.head()"
]
},
{
"cell_type": "code",
"execution_count": 239,
"id": "2c3ae71a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>2000</th>\n",
" <th>2001</th>\n",
" <th>2002</th>\n",
" <th>2003</th>\n",
" <th>2004</th>\n",
" <th>2005</th>\n",
" <th>2006</th>\n",
" <th>2007</th>\n",
" <th>2008</th>\n",
" <th>2009</th>\n",
" <th>2010</th>\n",
" <th>2011</th>\n",
" <th>2012</th>\n",
" <th>2013</th>\n",
" <th>2014</th>\n",
" <th>2015</th>\n",
" <th>2016</th>\n",
" <th>2017</th>\n",
" <th>2018</th>\n",
" <th>2019</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>-0.0598</td>\n",
" <td>-0.063481</td>\n",
" <td>0.321695</td>\n",
" <td>0.049136</td>\n",
" <td>-0.001274</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>-0.045373</td>\n",
" <td>0.02851</td>\n",
" <td>0.282777</td>\n",
" <td>0</td>\n",
" <td>-0.070649</td>\n",
" <td>0.004498</td>\n",
" <td>0.021944</td>\n",
" <td>0.087911</td>\n",
" <td>0.105078</td>\n",
" <td>0.80738</td>\n",
" <td>0.041863</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 2000 2001 2002 2003 2004 2005 2006 2007 2008 \\\n",
"0 0 0 -0.0598 -0.063481 0.321695 0.049136 -0.001274 0 0 \n",
"\n",
" 2009 2010 2011 2012 2013 2014 2015 2016 \\\n",
"0 -0.045373 0.02851 0.282777 0 -0.070649 0.004498 0.021944 0.087911 \n",
"\n",
" 2017 2018 2019 \n",
"0 0.105078 0.80738 0.041863 "
]
},
"execution_count": 239,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"mean_pct = pd.DataFrame(pct_change_df.mean())[1:]\n",
"mean_pct = mean_pct.transpose()\n",
"mean_pct['2000']=0\n",
"mean_pct['2001']=0\n",
"mean_pct['2007']=0\n",
"mean_pct['2008']=0\n",
"mean_pct['2012']=0\n",
"mean_pct"
]
},
{
"cell_type": "code",
"execution_count": 246,
"id": "ffa16f0d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>year</th>\n",
" <th>average_risk</th>\n",
" <th>min_risk</th>\n",
" <th>max_risk</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2000</td>\n",
" <td>7.705748e+05</td>\n",
" <td>41249.682833</td>\n",
" <td>2.570136e+07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2001</td>\n",
" <td>7.705748e+05</td>\n",
" <td>41249.682833</td>\n",
" <td>2.570136e+07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2002</td>\n",
" <td>7.244943e+05</td>\n",
" <td>38782.948757</td>\n",
" <td>2.416442e+07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2003</td>\n",
" <td>7.216579e+05</td>\n",
" <td>38631.113273</td>\n",
" <td>2.406981e+07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2004</td>\n",
" <td>1.018465e+06</td>\n",
" <td>54519.485534</td>\n",
" <td>3.396935e+07</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" year average_risk min_risk max_risk\n",
"0 2000 7.705748e+05 41249.682833 2.570136e+07\n",
"1 2001 7.705748e+05 41249.682833 2.570136e+07\n",
"2 2002 7.244943e+05 38782.948757 2.416442e+07\n",
"3 2003 7.216579e+05 38631.113273 2.406981e+07\n",
"4 2004 1.018465e+06 54519.485534 3.396935e+07"
]
},
"execution_count": 246,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pct_change_json = {}\n",
"for el in mean_pct.columns:\n",
" pct_change_json[el]=mean_pct[el].iloc[0]\n",
" \n",
"#estimate total impact to project\n",
"total_risk_impact = water_risk_impact.sum()\n",
"\n",
"##RISK OVER TIME\n",
"#project total risk\n",
"average_risk = total_risk_impact['wr_mean']\n",
"pr_average_risk = [(average_risk + pct_change_json[f'{year}']*average_risk) for year in range(2000,2020)]\n",
"\n",
"#project max risk\n",
"max_risk = total_risk_impact['wr_max']\n",
"pr_max_risk = [(max_risk + pct_change_json[f'{year}']*max_risk) for year in range(2000,2020)]\n",
"\n",
"#project min risk\n",
"min_risk = total_risk_impact['wr_min']\n",
"pr_min_risk = [(min_risk + pct_change_json[f'{year}']*min_risk) for year in range(2000,2020)]\n",
"\n",
"#generate dataframe\n",
"df_risk = pd.DataFrame()\n",
"df_risk['year']=[year for year in range(2000,2020)]\n",
"df_risk['average_risk']=pr_average_risk\n",
"df_risk['min_risk']=pr_min_risk\n",
"df_risk['max_risk']=pr_max_risk\n",
"df_risk.head()\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 256,
"id": "effcfa0e",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
"BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
"BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
]
}
],
"source": [
"df_risk['year'] = pd.to_datetime(df_risk['year'], format='%Y')\n",
"\n",
"source = ColumnDataSource(df_risk)\n",
"\n",
"p_risk = figure(x_axis_type=\"datetime\")\n",
"\n",
"p_risk.line(x='year', y='average_risk', line_width=2, source=source, legend='Average impact')\n",
"p_risk.line(x='year', y='min_risk', line_width=2, source=source, color=Spectral10[5], legend='Min impact')\n",
"p_risk.line(x='year', y='max_risk', line_width=2, source=source, color=Spectral10[9], legend='Max impact')\n",
"\n",
"p_risk.title.text = 'Unsustainable water use risk over time'\n",
"p_risk.yaxis.axis_label = 'm3 / ha'"
]
},
{
"cell_type": "code",
"execution_count": 254,
"id": "2bdc7a04",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>year</th>\n",
" <th>average_imp</th>\n",
" <th>min_imp</th>\n",
" <th>max_imp</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2000</td>\n",
" <td>7.705748e+05</td>\n",
" <td>41249.682833</td>\n",
" <td>2.483171e+10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2001</td>\n",
" <td>7.705748e+05</td>\n",
" <td>41249.682833</td>\n",
" <td>2.483171e+10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2002</td>\n",
" <td>7.244943e+05</td>\n",
" <td>38782.948757</td>\n",
" <td>2.334677e+10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2003</td>\n",
" <td>7.216579e+05</td>\n",
" <td>38631.113273</td>\n",
" <td>2.325537e+10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2004</td>\n",
" <td>1.018465e+06</td>\n",
" <td>54519.485534</td>\n",
" <td>3.281994e+10</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" year average_imp min_imp max_imp\n",
"0 2000 7.705748e+05 41249.682833 2.483171e+10\n",
"1 2001 7.705748e+05 41249.682833 2.483171e+10\n",
"2 2002 7.244943e+05 38782.948757 2.334677e+10\n",
"3 2003 7.216579e+05 38631.113273 2.325537e+10\n",
"4 2004 1.018465e+06 54519.485534 3.281994e+10"
]
},
"execution_count": 254,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"##IMPACT OVER TIME\n",
"#project total risk\n",
"average_imp = total_risk_impact['wr_imp']\n",
"pr_average_imp = [(average_risk + pct_change_json[f'{year}']*average_risk) for year in range(2000,2020)]\n",
"\n",
"#project max risk\n",
"max_risk = total_risk_impact['wr_imp_max']\n",
"pr_max_imp = [(max_risk + pct_change_json[f'{year}']*max_risk) for year in range(2000,2020)]\n",
"\n",
"#project min risk\n",
"max_risk = total_risk_impact['wr_imp_max']\n",
"pr_min_imp = [(min_risk + pct_change_json[f'{year}']*min_risk) for year in range(2000,2020)]\n",
"\n",
"\n",
"#generate dataframe\n",
"df_imp = pd.DataFrame()\n",
"df_imp['year']=[year for year in range(2000,2020)]\n",
"df_imp['average_imp']=pr_average_imp\n",
"df_imp['min_imp']=pr_min_imp\n",
"df_imp['max_imp']=pr_max_imp\n",
"df_imp.head()"
]
},
{
"cell_type": "code",
"execution_count": 257,
"id": "f5ab525b",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
"BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
"BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
]
}
],
"source": [
"df_imp['year'] = pd.to_datetime(df_imp['year'], format='%Y')\n",
"\n",
"source = ColumnDataSource(df_imp)\n",
"\n",
"p_imp = figure(x_axis_type=\"datetime\")\n",
"\n",
"p_imp.line(x='year', y='average_imp', line_width=2, source=source, legend='Average impact')\n",
"p_imp.line(x='year', y='min_imp', line_width=2, source=source, color=Spectral10[5], legend='Min impact')\n",
"p_imp.line(x='year', y='max_imp', line_width=2, source=source, color=Spectral10[9], legend='Max impact')\n",
"\n",
"p_imp.title.text = 'Unsustainable water use impact over time'\n",
"p_imp.yaxis.axis_label = 'm3'"
]
},
{
"cell_type": "code",
"execution_count": 258,
"id": "38c42e4f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" <div class=\"bk-root\" id=\"81d1124f-f73f-4e97-870a-2ea1c1eec701\" data-root-id=\"8315\"></div>\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"(function(root) {\n",
" function embed_document(root) {\n",
" \n",
" var docs_json = {\"b9139404-48e0-48a6-94f5-ec6682a4343f\":{\"roots\":{\"references\":[{\"attributes\":{\"children\":[{\"id\":\"8314\"},{\"id\":\"8312\"}]},\"id\":\"8315\",\"type\":\"Column\"},{\"attributes\":{},\"id\":\"8057\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"base\":60,\"mantissas\":[1,2,5,10,15,20,30],\"max_interval\":1800000.0,\"min_interval\":1000.0,\"num_minor_ticks\":0},\"id\":\"8200\",\"type\":\"AdaptiveTicker\"},{\"attributes\":{\"overlay\":{\"id\":\"8062\"}},\"id\":\"8058\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"label\":{\"value\":\"Min impact\"},\"renderers\":[{\"id\":\"8216\"}]},\"id\":\"8239\",\"type\":\"LegendItem\"},{\"attributes\":{\"months\":[0,6]},\"id\":\"8209\",\"type\":\"MonthsTicker\"},{\"attributes\":{\"children\":[[{\"id\":\"8039\"},0,0],[{\"id\":\"8154\"},0,1]]},\"id\":\"8312\",\"type\":\"GridBox\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"8062\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"8053\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"8193\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"days\":[1,15]},\"id\":\"8205\",\"type\":\"DaysTicker\"},{\"attributes\":{\"toolbar\":{\"id\":\"8313\"},\"toolbar_location\":\"above\"},\"id\":\"8314\",\"type\":\"ToolbarBox\"},{\"attributes\":{\"months\":[0,2,4,6,8,10]},\"id\":\"8207\",\"type\":\"MonthsTicker\"},{\"attributes\":{},\"id\":\"8195\",\"type\":\"DatetimeTickFormatter\"},{\"attributes\":{\"line_color\":\"#1f77b4\",\"line_width\":2,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"average_risk\"}},\"id\":\"8071\",\"type\":\"Line\"},{\"attributes\":{\"data_source\":{\"id\":\"8038\"},\"glyph\":{\"id\":\"8099\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"8100\"},\"selection_glyph\":null,\"view\":{\"id\":\"8102\"}},\"id\":\"8101\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"8052\"},\"dimension\":1,\"ticker\":null},\"id\":\"8055\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"8059\",\"type\":\"SaveTool\"},{\"attributes\":{\"base\":24,\"mantissas\":[1,2,4,6,8,12],\"max_interval\":43200000.0,\"min_interval\":3600000.0,\"num_minor_ticks\":0},\"id\":\"8201\",\"type\":\"AdaptiveTicker\"},{\"attributes\":{},\"id\":\"8210\",\"type\":\"YearsTicker\"},{\"attributes\":{},\"id\":\"8061\",\"type\":\"HelpTool\"},{\"attributes\":{\"days\":[1,8,15,22]},\"id\":\"8204\",\"type\":\"DaysTicker\"},{\"attributes\":{\"mantissas\":[1,2,5],\"max_interval\":500.0,\"num_minor_ticks\":0},\"id\":\"8199\",\"type\":\"AdaptiveTicker\"},{\"attributes\":{},\"id\":\"8060\",\"type\":\"ResetTool\"},{\"attributes\":{\"text\":\"Unsustainable water use impact over time\"},\"id\":\"8190\",\"type\":\"Title\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"8056\"},{\"id\":\"8057\"},{\"id\":\"8058\"},{\"id\":\"8059\"},{\"id\":\"8060\"},{\"id\":\"8061\"}]},\"id\":\"8063\",\"type\":\"Toolbar\"},{\"attributes\":{\"months\":[0,1,2,3,4,5,6,7,8,9,10,11]},\"id\":\"8206\",\"type\":\"MonthsTicker\"},{\"attributes\":{},\"id\":\"8196\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"8056\",\"type\":\"PanTool\"},{\"attributes\":{\"days\":[1,4,7,10,13,16,19,22,25,28]},\"id\":\"8203\",\"type\":\"DaysTicker\"},{\"attributes\":{\"months\":[0,4,8]},\"id\":\"8208\",\"type\":\"MonthsTicker\"},{\"attributes\":{},\"id\":\"8197\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"days\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]},\"id\":\"8202\",\"type\":\"DaysTicker\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"8171\"},{\"id\":\"8172\"},{\"id\":\"8173\"},{\"id\":\"8174\"},{\"id\":\"8175\"},{\"id\":\"8176\"}]},\"id\":\"8178\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"8174\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"8168\",\"type\":\"BasicTicker\"},{\"attributes\":{\"data_source\":{\"id\":\"8153\"},\"glyph\":{\"id\":\"8214\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"8215\"},\"selection_glyph\":null,\"view\":{\"id\":\"8217\"}},\"id\":\"8216\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"months\":[0,6]},\"id\":\"8094\",\"type\":\"MonthsTicker\"},{\"attributes\":{\"axis_label\":\"m3\",\"formatter\":{\"id\":\"8193\"},\"ticker\":{\"id\":\"8168\"}},\"id\":\"8167\",\"type\":\"LinearAxis\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"line_width\":2,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"average_imp\"}},\"id\":\"8187\",\"type\":\"Line\"},{\"attributes\":{\"axis\":{\"id\":\"8167\"},\"dimension\":1,\"ticker\":null},\"id\":\"8170\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"8038\"}},\"id\":\"8102\",\"type\":\"CDSView\"},{\"attributes\":{\"text\":\"Unsustainable water use risk over time\"},\"id\":\"8075\",\"type\":\"Title\"},{\"attributes\":{\"data_source\":{\"id\":\"8038\"},\"glyph\":{\"id\":\"8071\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"8072\"},\"selection_glyph\":null,\"view\":{\"id\":\"8074\"}},\"id\":\"8073\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#9e0142\",\"line_width\":2,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"max_imp\"}},\"id\":\"8242\",\"type\":\"Line\"},{\"attributes\":{\"source\":{\"id\":\"8038\"}},\"id\":\"8074\",\"type\":\"CDSView\"},{\"attributes\":{\"line_color\":\"#9e0142\",\"line_width\":2,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"max_imp\"}},\"id\":\"8241\",\"type\":\"Line\"},{\"attributes\":{\"label\":{\"value\":\"Max impact\"},\"renderers\":[{\"id\":\"8128\"}]},\"id\":\"8151\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"8157\",\"type\":\"DataRange1d\"},{\"attributes\":{\"months\":[0,2,4,6,8,10]},\"id\":\"8092\",\"type\":\"MonthsTicker\"},{\"attributes\":{\"source\":{\"id\":\"8153\"}},\"id\":\"8217\",\"type\":\"CDSView\"},{\"attributes\":{\"days\":[1,4,7,10,13,16,19,22,25,28]},\"id\":\"8088\",\"type\":\"DaysTicker\"},{\"attributes\":{},\"id\":\"8042\",\"type\":\"DataRange1d\"},{\"attributes\":{\"formatter\":{\"id\":\"8195\"},\"ticker\":{\"id\":\"8164\"}},\"id\":\"8163\",\"type\":\"DatetimeAxis\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"line_width\":2,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"average_risk\"}},\"id\":\"8072\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"8159\",\"type\":\"LinearScale\"},{\"attributes\":{\"label\":{\"value\":\"Min impact\"},\"renderers\":[{\"id\":\"8101\"}]},\"id\":\"8124\",\"type\":\"LegendItem\"},{\"attributes\":{\"line_color\":\"#9e0142\",\"line_width\":2,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"max_risk\"}},\"id\":\"8126\",\"type\":\"Line\"},{\"attributes\":{\"below\":[{\"id\":\"8048\"}],\"center\":[{\"id\":\"8051\"},{\"id\":\"8055\"},{\"id\":\"8096\"}],\"left\":[{\"id\":\"8052\"}],\"plot_width\":450,\"renderers\":[{\"id\":\"8073\"},{\"id\":\"8101\"},{\"id\":\"8128\"}],\"title\":{\"id\":\"8075\"},\"toolbar\":{\"id\":\"8063\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"8040\"},\"x_scale\":{\"id\":\"8044\"},\"y_range\":{\"id\":\"8042\"},\"y_scale\":{\"id\":\"8046\"}},\"id\":\"8039\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"8078\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"label\":{\"value\":\"Average impact\"},\"renderers\":[{\"id\":\"8188\"}]},\"id\":\"8212\",\"type\":\"LegendItem\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#9e0142\",\"line_width\":2,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"max_risk\"}},\"id\":\"8127\",\"type\":\"Line\"},{\"attributes\":{\"items\":[{\"id\":\"8212\"},{\"id\":\"8239\"},{\"id\":\"8266\"}]},\"id\":\"8211\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"8095\",\"type\":\"YearsTicker\"},{\"attributes\":{\"formatter\":{\"id\":\"8080\"},\"ticker\":{\"id\":\"8049\"}},\"id\":\"8048\",\"type\":\"DatetimeAxis\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#fee08b\",\"line_width\":2,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"min_imp\"}},\"id\":\"8215\",\"type\":\"Line\"},{\"attributes\":{\"line_color\":\"#fee08b\",\"line_width\":2,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"min_imp\"}},\"id\":\"8214\",\"type\":\"Line\"},{\"attributes\":{\"axis_label\":\"m3 / ha\",\"formatter\":{\"id\":\"8078\"},\"ticker\":{\"id\":\"8053\"}},\"id\":\"8052\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data_source\":{\"id\":\"8038\"},\"glyph\":{\"id\":\"8126\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"8127\"},\"selection_glyph\":null,\"view\":{\"id\":\"8129\"}},\"id\":\"8128\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"label\":{\"value\":\"Average impact\"},\"renderers\":[{\"id\":\"8073\"}]},\"id\":\"8097\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"8172\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"toolbars\":[{\"id\":\"8063\"},{\"id\":\"8178\"}],\"tools\":[{\"id\":\"8056\"},{\"id\":\"8057\"},{\"id\":\"8058\"},{\"id\":\"8059\"},{\"id\":\"8060\"},{\"id\":\"8061\"},{\"id\":\"8171\"},{\"id\":\"8172\"},{\"id\":\"8173\"},{\"id\":\"8174\"},{\"id\":\"8175\"},{\"id\":\"8176\"}]},\"id\":\"8313\",\"type\":\"ProxyToolbar\"},{\"attributes\":{\"axis\":{\"id\":\"8163\"},\"ticker\":null},\"id\":\"8166\",\"type\":\"Grid\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#fee08b\",\"line_width\":2,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"min_risk\"}},\"id\":\"8100\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"8044\",\"type\":\"LinearScale\"},{\"attributes\":{\"days\":[1,15]},\"id\":\"8090\",\"type\":\"DaysTicker\"},{\"attributes\":{\"num_minor_ticks\":5,\"tickers\":[{\"id\":\"8084\"},{\"id\":\"8085\"},{\"id\":\"8086\"},{\"id\":\"8087\"},{\"id\":\"8088\"},{\"id\":\"8089\"},{\"id\":\"8090\"},{\"id\":\"8091\"},{\"id\":\"8092\"},{\"id\":\"8093\"},{\"id\":\"8094\"},{\"id\":\"8095\"}]},\"id\":\"8049\",\"type\":\"DatetimeTicker\"},{\"attributes\":{\"data\":{\"average_imp\":{\"__ndarray__\":\"RjBNhh2EJ0FGME2GHYQnQbCwW6scHCZBX6Kn3vMFJkHOt+AYwRQvQdG/CcDqqyhB+xCgrnJ8J0FGME2GHYQnQUYwTYYdhCdB2L2zF/dyJkHluYoAwC8oQbhLbrN2Ki5BRjBNhh2EJ0FRtR02zdolQZLCeo4xnydBH/uuDzgIKEGG4tQTWZUpQcRMEgWy/ClB3EqGW1FANUEaMzGLIoAoQQ==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[20]},\"index\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19],\"max_imp\":{\"__ndarray__\":\"PO80T1cgF0I87zRPVyAXQjX1aOFNvhVCeKVTGYOoFULv+HQW4pAeQtDLE4E9QxhC0FuA/8wYF0I87zRPVyAXQjzvNE9XIBdCt/RIzbcTFkKCxMOSIckXQljGC755qh1CPO80T1cgF0LXo62FE34VQtBEFHT4OhdCAKzoWkGiF0LdwYttzSgZQou19uJvjhlCWisuHSfmJEKjL4oOLxgYQg==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[20]},\"min_imp\":{\"__ndarray__\":\"zVvF2TUk5EDNW8XZNSTkQK1dOFze7+JA6MTtn+Pc4kA/LX6J757qQJBXSUaQIeVAij6drqQd5EDNW8XZNSTkQM1bxdk1JORAGuBeE0I640ALTqwFN7fkQCWeaDlE1ulAzVvF2TUk5EDoTRYy7rfiQJ9FZB1nO+RAhjrkUluV5EDey1cZf+nlQDo+nmMDQuZA5KVxlJ0z8kAc9eR6EPzkQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[20]},\"year\":{\"__ndarray__\":\"AACA9VmNa0IAAIDm9HhsQgAAAAzrY21CAACAMeFObkIAAABX1zlvQgAAACS5EnBCAADANjSIcEIAAIBJr/1wQgAAQFwqc3FCAADA1PfocUIAAIDncl5yQgAAQPrt03JCAAAADWlJc0IAAICFNr9zQgAAQJixNHRCAAAAqyyqdEIAAMC9px91QgAAQDZ1lXVCAAAASfAKdkIAAMBba4B2Qg==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[20]}},\"selected\":{\"id\":\"8196\"},\"selection_policy\":{\"id\":\"8197\"}},\"id\":\"8153\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"source\":{\"id\":\"8038\"}},\"id\":\"8129\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"8155\",\"type\":\"DataRange1d\"},{\"attributes\":{\"days\":[1,8,15,22]},\"id\":\"8089\",\"type\":\"DaysTicker\"},{\"attributes\":{},\"id\":\"8176\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"8082\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"axis\":{\"id\":\"8048\"},\"ticker\":null},\"id\":\"8051\",\"type\":\"Grid\"},{\"attributes\":{\"num_minor_ticks\":5,\"tickers\":[{\"id\":\"8199\"},{\"id\":\"8200\"},{\"id\":\"8201\"},{\"id\":\"8202\"},{\"id\":\"8203\"},{\"id\":\"8204\"},{\"id\":\"8205\"},{\"id\":\"8206\"},{\"id\":\"8207\"},{\"id\":\"8208\"},{\"id\":\"8209\"},{\"id\":\"8210\"}]},\"id\":\"8164\",\"type\":\"DatetimeTicker\"},{\"attributes\":{},\"id\":\"8161\",\"type\":\"LinearScale\"},{\"attributes\":{\"months\":[0,4,8]},\"id\":\"8093\",\"type\":\"MonthsTicker\"},{\"attributes\":{\"line_color\":\"#fee08b\",\"line_width\":2,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"min_risk\"}},\"id\":\"8099\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"8081\",\"type\":\"Selection\"},{\"attributes\":{\"source\":{\"id\":\"8153\"}},\"id\":\"8244\",\"type\":\"CDSView\"},{\"attributes\":{\"overlay\":{\"id\":\"8177\"}},\"id\":\"8173\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"below\":[{\"id\":\"8163\"}],\"center\":[{\"id\":\"8166\"},{\"id\":\"8170\"},{\"id\":\"8211\"}],\"left\":[{\"id\":\"8167\"}],\"plot_width\":450,\"renderers\":[{\"id\":\"8188\"},{\"id\":\"8216\"},{\"id\":\"8243\"}],\"title\":{\"id\":\"8190\"},\"toolbar\":{\"id\":\"8178\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"8155\"},\"x_scale\":{\"id\":\"8159\"},\"y_range\":{\"id\":\"8157\"},\"y_scale\":{\"id\":\"8161\"}},\"id\":\"8154\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"8046\",\"type\":\"LinearScale\"},{\"attributes\":{\"months\":[0,1,2,3,4,5,6,7,8,9,10,11]},\"id\":\"8091\",\"type\":\"MonthsTicker\"},{\"attributes\":{},\"id\":\"8040\",\"type\":\"DataRange1d\"},{\"attributes\":{\"line_color\":\"#1f77b4\",\"line_width\":2,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"average_imp\"}},\"id\":\"8186\",\"type\":\"Line\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"8177\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"8080\",\"type\":\"DatetimeTickFormatter\"},{\"attributes\":{\"label\":{\"value\":\"Max impact\"},\"renderers\":[{\"id\":\"8243\"}]},\"id\":\"8266\",\"type\":\"LegendItem\"},{\"attributes\":{\"items\":[{\"id\":\"8097\"},{\"id\":\"8124\"},{\"id\":\"8151\"}]},\"id\":\"8096\",\"type\":\"Legend\"},{\"attributes\":{\"days\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]},\"id\":\"8087\",\"type\":\"DaysTicker\"},{\"attributes\":{\"data\":{\"average_risk\":{\"__ndarray__\":\"RjBNhh2EJ0FGME2GHYQnQbCwW6scHCZBX6Kn3vMFJkHOt+AYwRQvQdG/CcDqqyhB+xCgrnJ8J0FGME2GHYQnQUYwTYYdhCdB2L2zF/dyJkHluYoAwC8oQbhLbrN2Ki5BRjBNhh2EJ0FRtR02zdolQZLCeo4xnydBH/uuDzgIKEGG4tQTWZUpQcRMEgWy/ClB3EqGW1FANUEaMzGLIoAoQQ==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[20]},\"index\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19],\"max_risk\":{\"__ndarray__\":\"QA80E7+CeEFADzQTv4J4QcymeR6EC3dB+OfwYGv0dkFMA9s+pjKAQYeAbjoPt3lBc/LzNcF6eEFADzQTv4J4QUAPNBO/gnhBlgsz/Apmd0FPZGQBpDV5Qbd9wzQZcX9BQA80E7+CeEHm5ah7ccd2Qf8vIE/4nnhBDKQ/BnAMeUF8DtQiXap6QR5PtB4VFntB+6Oa4mwmhkFJjZvzbIl5QQ==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[20]},\"min_risk\":{\"__ndarray__\":\"zVvF2TUk5EDNW8XZNSTkQK1dOFze7+JA6MTtn+Pc4kA/LX6J757qQJBXSUaQIeVAij6drqQd5EDNW8XZNSTkQM1bxdk1JORAGuBeE0I640ALTqwFN7fkQCWeaDlE1ulAzVvF2TUk5EDoTRYy7rfiQJ9FZB1nO+RAhjrkUluV5EDey1cZf+nlQDo+nmMDQuZA5KVxlJ0z8kAc9eR6EPzkQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[20]},\"year\":{\"__ndarray__\":\"AACA9VmNa0IAAIDm9HhsQgAAAAzrY21CAACAMeFObkIAAABX1zlvQgAAACS5EnBCAADANjSIcEIAAIBJr/1wQgAAQFwqc3FCAADA1PfocUIAAIDncl5yQgAAQPrt03JCAAAADWlJc0IAAICFNr9zQgAAQJixNHRCAAAAqyyqdEIAAMC9px91QgAAQDZ1lXVCAAAASfAKdkIAAMBba4B2Qg==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[20]}},\"selected\":{\"id\":\"8081\"},\"selection_policy\":{\"id\":\"8082\"}},\"id\":\"8038\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"mantissas\":[1,2,5],\"max_interval\":500.0,\"num_minor_ticks\":0},\"id\":\"8084\",\"type\":\"AdaptiveTicker\"},{\"attributes\":{\"base\":24,\"mantissas\":[1,2,4,6,8,12],\"max_interval\":43200000.0,\"min_interval\":3600000.0,\"num_minor_ticks\":0},\"id\":\"8086\",\"type\":\"AdaptiveTicker\"},{\"attributes\":{},\"id\":\"8175\",\"type\":\"ResetTool\"},{\"attributes\":{\"data_source\":{\"id\":\"8153\"},\"glyph\":{\"id\":\"8241\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"8242\"},\"selection_glyph\":null,\"view\":{\"id\":\"8244\"}},\"id\":\"8243\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"base\":60,\"mantissas\":[1,2,5,10,15,20,30],\"max_interval\":1800000.0,\"min_interval\":1000.0,\"num_minor_ticks\":0},\"id\":\"8085\",\"type\":\"AdaptiveTicker\"},{\"attributes\":{\"data_source\":{\"id\":\"8153\"},\"glyph\":{\"id\":\"8186\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"8187\"},\"selection_glyph\":null,\"view\":{\"id\":\"8189\"}},\"id\":\"8188\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"source\":{\"id\":\"8153\"}},\"id\":\"8189\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"8171\",\"type\":\"PanTool\"}],\"root_ids\":[\"8315\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
" var render_items = [{\"docid\":\"b9139404-48e0-48a6-94f5-ec6682a4343f\",\"root_ids\":[\"8315\"],\"roots\":{\"8315\":\"81d1124f-f73f-4e97-870a-2ea1c1eec701\"}}];\n",
" root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
"\n",
" }\n",
" if (root.Bokeh !== undefined) {\n",
" embed_document(root);\n",
" } else {\n",
" var attempts = 0;\n",
" var timer = setInterval(function(root) {\n",
" if (root.Bokeh !== undefined) {\n",
" clearInterval(timer);\n",
" embed_document(root);\n",
" } else {\n",
" attempts++;\n",
" if (attempts > 100) {\n",
" clearInterval(timer);\n",
" console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
" }\n",
" }\n",
" }, 10, root)\n",
" }\n",
"})(window);"
],
"application/vnd.bokehjs_exec.v0+json": ""
},
"metadata": {
"application/vnd.bokehjs_exec.v0+json": {
"id": "8315"
}
},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div style=\"display: table;\"><div style=\"display: table-row;\"><div style=\"display: table-cell;\"><b title=\"bokeh.models.layouts.Column\">Column</b>(</div><div style=\"display: table-cell;\">id = '8315', <span id=\"8653\" style=\"cursor: pointer;\">…)</span></div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">align = 'start',</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">aspect_ratio = None,</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">background = None,</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">children = [ToolbarBox(id='8314', ...), GridBox(id='8312', ...)],</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">css_classes = [],</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">disabled = False,</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">height = None,</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">height_policy = 'auto',</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_event_callbacks = {},</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_property_callbacks = {},</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">margin = (0, 0, 0, 0),</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">max_height = None,</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">max_width = None,</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">min_height = None,</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">min_width = None,</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">name = None,</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">rows = 'auto',</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">sizing_mode = None,</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">spacing = 0,</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">subscribed_events = [],</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">tags = [],</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">visible = True,</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">width = None,</div></div><div class=\"8652\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">width_policy = 'auto')</div></div></div>\n",
"<script>\n",
"(function() {\n",
" var expanded = false;\n",
" var ellipsis = document.getElementById(\"8653\");\n",
" ellipsis.addEventListener(\"click\", function() {\n",
" var rows = document.getElementsByClassName(\"8652\");\n",
" for (var i = 0; i < rows.length; i++) {\n",
" var el = rows[i];\n",
" el.style.display = expanded ? \"none\" : \"table-row\";\n",
" }\n",
" ellipsis.innerHTML = expanded ? \"…)\" : \"‹‹‹\";\n",
" expanded = !expanded;\n",
" });\n",
"})();\n",
"</script>\n"
],
"text/plain": [
"Column(id='8315', ...)"
]
},
"execution_count": 258,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Make Dashboard with Grid Layout:\n",
"pandas_bokeh.plot_grid([[p_risk, p_imp]], plot_width=450)"
]
},
{
"cell_type": "code",
"execution_count": 265,
"id": "317cd492",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Country</th>\n",
" <th>wr_mean</th>\n",
" <th>wr_imp</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>India</td>\n",
" <td>45.279566</td>\n",
" <td>2.218699e+04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Thailand</td>\n",
" <td>73.810405</td>\n",
" <td>2.288123e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Indonesia</td>\n",
" <td>52.100767</td>\n",
" <td>1.354620e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>Cote d'Ivoire</td>\n",
" <td>2.733245</td>\n",
" <td>3.006569e+03</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Vietnam</td>\n",
" <td>100.613764</td>\n",
" <td>8.149715e+04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Malaysia</td>\n",
" <td>226.718707</td>\n",
" <td>1.677718e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>Liberia</td>\n",
" <td>201.492037</td>\n",
" <td>4.634317e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>India</td>\n",
" <td>296.645033</td>\n",
" <td>3.559740e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>Thailand</td>\n",
" <td>84.117894</td>\n",
" <td>8.411789e+04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>Thailand</td>\n",
" <td>471.552868</td>\n",
" <td>3.489491e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>China</td>\n",
" <td>30.034120</td>\n",
" <td>1.201365e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>Vietnam</td>\n",
" <td>4.941625</td>\n",
" <td>7.412437e+03</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>Bangladesh</td>\n",
" <td>8.558963</td>\n",
" <td>1.198255e+04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>Turkey</td>\n",
" <td>24.986441</td>\n",
" <td>2.998373e+04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>India</td>\n",
" <td>251.224800</td>\n",
" <td>1.871625e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>United states</td>\n",
" <td>58.515713</td>\n",
" <td>2.340629e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>India</td>\n",
" <td>251.224800</td>\n",
" <td>4.522046e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>Brazil</td>\n",
" <td>3.076831</td>\n",
" <td>4.922930e+03</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>Vietnam</td>\n",
" <td>4.941625</td>\n",
" <td>5.435787e+03</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>Uzbekistan</td>\n",
" <td>147.928929</td>\n",
" <td>8.875736e+04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>China</td>\n",
" <td>136.369093</td>\n",
" <td>6.545716e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>China</td>\n",
" <td>6.568878</td>\n",
" <td>2.693240e+04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>China</td>\n",
" <td>6.549618</td>\n",
" <td>2.554351e+04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>Greece</td>\n",
" <td>39.835553</td>\n",
" <td>1.314573e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>Australia</td>\n",
" <td>14.815337</td>\n",
" <td>4.740908e+04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>China</td>\n",
" <td>192.058552</td>\n",
" <td>5.953815e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>30</th>\n",
" <td>United states</td>\n",
" <td>36.964068</td>\n",
" <td>1.108922e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31</th>\n",
" <td>China</td>\n",
" <td>337.919525</td>\n",
" <td>9.123827e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>32</th>\n",
" <td>Australia</td>\n",
" <td>3.319580</td>\n",
" <td>8.962866e+03</td>\n",
" </tr>\n",
" <tr>\n",
" <th>33</th>\n",
" <td>China</td>\n",
" <td>105821.405660</td>\n",
" <td>1.904785e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>34</th>\n",
" <td>Italy</td>\n",
" <td>15155.106394</td>\n",
" <td>1.197253e+07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>35</th>\n",
" <td>Vietnam</td>\n",
" <td>6424.374577</td>\n",
" <td>1.670337e+06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>36</th>\n",
" <td>Thailand</td>\n",
" <td>2564.167033</td>\n",
" <td>4.615501e+05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>37</th>\n",
" <td>Korea</td>\n",
" <td>409.754392</td>\n",
" <td>6.556070e+04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38</th>\n",
" <td>United States</td>\n",
" <td>27188.648381</td>\n",
" <td>2.175092e+07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>39</th>\n",
" <td>Brazil</td>\n",
" <td>17666.946846</td>\n",
" <td>8.480134e+06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40</th>\n",
" <td>Australia</td>\n",
" <td>95931.462055</td>\n",
" <td>3.357601e+07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>41</th>\n",
" <td>Argentina</td>\n",
" <td>19440.327613</td>\n",
" <td>2.721646e+06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>42</th>\n",
" <td>Canada</td>\n",
" <td>29975.149161</td>\n",
" <td>3.746894e+06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>43</th>\n",
" <td>Australia</td>\n",
" <td>202983.095987</td>\n",
" <td>3.247730e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>44</th>\n",
" <td>Australia</td>\n",
" <td>202983.095987</td>\n",
" <td>1.603566e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>45</th>\n",
" <td>Burundi</td>\n",
" <td>40687.835938</td>\n",
" <td>2.766773e+07</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Country wr_mean wr_imp\n",
"4 India 45.279566 2.218699e+04\n",
"5 Thailand 73.810405 2.288123e+05\n",
"6 Indonesia 52.100767 1.354620e+05\n",
"7 Cote d'Ivoire 2.733245 3.006569e+03\n",
"8 Vietnam 100.613764 8.149715e+04\n",
"9 Malaysia 226.718707 1.677718e+05\n",
"10 Liberia 201.492037 4.634317e+05\n",
"11 India 296.645033 3.559740e+05\n",
"12 Thailand 84.117894 8.411789e+04\n",
"13 Thailand 471.552868 3.489491e+05\n",
"14 China 30.034120 1.201365e+05\n",
"15 Vietnam 4.941625 7.412437e+03\n",
"16 Bangladesh 8.558963 1.198255e+04\n",
"17 Turkey 24.986441 2.998373e+04\n",
"18 India 251.224800 1.871625e+05\n",
"19 United states 58.515713 2.340629e+05\n",
"20 India 251.224800 4.522046e+05\n",
"21 Brazil 3.076831 4.922930e+03\n",
"22 Vietnam 4.941625 5.435787e+03\n",
"23 Uzbekistan 147.928929 8.875736e+04\n",
"24 China 136.369093 6.545716e+05\n",
"25 China 6.568878 2.693240e+04\n",
"26 China 6.549618 2.554351e+04\n",
"27 Greece 39.835553 1.314573e+05\n",
"28 Australia 14.815337 4.740908e+04\n",
"29 China 192.058552 5.953815e+05\n",
"30 United states 36.964068 1.108922e+05\n",
"31 China 337.919525 9.123827e+05\n",
"32 Australia 3.319580 8.962866e+03\n",
"33 China 105821.405660 1.904785e+08\n",
"34 Italy 15155.106394 1.197253e+07\n",
"35 Vietnam 6424.374577 1.670337e+06\n",
"36 Thailand 2564.167033 4.615501e+05\n",
"37 Korea 409.754392 6.556070e+04\n",
"38 United States 27188.648381 2.175092e+07\n",
"39 Brazil 17666.946846 8.480134e+06\n",
"40 Australia 95931.462055 3.357601e+07\n",
"41 Argentina 19440.327613 2.721646e+06\n",
"42 Canada 29975.149161 3.746894e+06\n",
"43 Australia 202983.095987 3.247730e+08\n",
"44 Australia 202983.095987 1.603566e+08\n",
"45 Burundi 40687.835938 2.766773e+07"
]
},
"execution_count": 265,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"water_risk_impact[['Country','wr_mean','wr_imp']][4:]"
]
},
{
"cell_type": "code",
"execution_count": 266,
"id": "9f8c63f1",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" <div class=\"bk-root\" id=\"7047dda4-b5a6-4881-bdd6-37dc7cc95501\" data-root-id=\"9121\"></div>\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"(function(root) {\n",
" function embed_document(root) {\n",
" \n",
" var docs_json = {\"eeba9fd5-c487-4684-9651-611f36c6df86\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"9132\"}],\"center\":[{\"id\":\"9135\"},{\"id\":\"9139\"}],\"left\":[{\"id\":\"9136\"}],\"renderers\":[{\"id\":\"9158\"}],\"title\":{\"id\":\"9122\"},\"toolbar\":{\"id\":\"9147\"},\"x_range\":{\"id\":\"9124\"},\"x_scale\":{\"id\":\"9128\"},\"y_range\":{\"id\":\"9126\"},\"y_scale\":{\"id\":\"9130\"}},\"id\":\"9121\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"9130\",\"type\":\"LinearScale\"},{\"attributes\":{\"axis\":{\"id\":\"9132\"},\"ticker\":null},\"id\":\"9135\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"9137\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"9308\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"9126\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis_label\":\"Risk\",\"formatter\":{\"id\":\"9306\"},\"ticker\":{\"id\":\"9133\"}},\"id\":\"9132\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"9140\",\"type\":\"PanTool\"},{\"attributes\":{\"text\":\"\"},\"id\":\"9122\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"9143\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"9306\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"9307\",\"type\":\"Selection\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"wr_mean\"},\"y\":{\"field\":\"wr_imp\"}},\"id\":\"9156\",\"type\":\"Circle\"},{\"attributes\":{\"overlay\":{\"id\":\"9146\"}},\"id\":\"9142\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"9141\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"9124\",\"type\":\"DataRange1d\"},{\"attributes\":{\"source\":{\"id\":\"9154\"}},\"id\":\"9159\",\"type\":\"CDSView\"},{\"attributes\":{\"data\":{\"index\":[4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45],\"wr_imp\":{\"__ndarray__\":\"f+KYLb+q1UCv3q4KYu4LQUCs2fQviQBBA91LhCN9p0AxJGpikuXzQMlpSL/eegRBdmInvh5JHEHfhYMoGLoVQdDzPE9eifRALrrofFRMFUFJirmxh1T9QGq8evlv9LxAzATRMkZnx0BcJxim7kfdQGnDRc7T2AZBqTfczXaSDEETL6qOspkbQY3wECruOrNAGnnRlMk7tUC3bdu2Vav1QJ6tvEvX+SNBtZynphlN2kCvzNmy4PHYQAAAAJgKDABBWO5phCIm50AkSZIFaysiQQAAwETDEvtAAACQb/3XK0FGI1bQboHBQJGaYITxtKZBvamlwfbVZkGHdd9jwXw5QQn3mEO4KxxB3yylPosB8ECogkdrSL50QZQEjM+wLGBBOlTBXaICgEGDT9TutsNEQRRilNImlkxBTyWUWaRbs0GlsahLsh2jQQAAAAfRYnpB\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[42]},\"wr_mean\":{\"__ndarray__\":\"+Ap4zsijRkCmoYys3XNSQKmiAvDlDEpADdfyfa/dBUDuwsTpRydZQMYKcqb/VmxAxU7sxL4vaUB6fBcOUopyQJVLuZSLB1VAuuiii9h4fUDYl1cavAg+QEbVnFM5xBNArsFiazAeIUCMSlxhh/w4QDSF+o4xZ29AKsAW3wJCTUA0hfqOMWdvQL/Xcc9ZnQhARtWcUznEE0BiU2nIuX1iQCT3yZzPC2FAGHOmBIhGGkAfCfAbzzIaQE422WTz6kNAPo2w3HOhLUCogzqo3wFoQFVVVZVme0JAAAAAYLYedUD54zzof44KQGG8lX3W1flA/9BTno2ZzUCVPE7kXxi5QBIWZ4VVCKRAmBTV/RGceUBx2hN/KY3aQMDiHZm8QNFA2DqUZLdr90CGip33FPzSQD+H24vJRd1Ao6qUxDjHCEGjqpTEOMcIQQAAAMD63eNA\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[42]}},\"selected\":{\"id\":\"9307\"},\"selection_policy\":{\"id\":\"9308\"}},\"id\":\"9154\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"9140\"},{\"id\":\"9141\"},{\"id\":\"9142\"},{\"id\":\"9143\"},{\"id\":\"9144\"},{\"id\":\"9145\"}]},\"id\":\"9147\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"9145\",\"type\":\"HelpTool\"},{\"attributes\":{\"data_source\":{\"id\":\"9154\"},\"glyph\":{\"id\":\"9156\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"9157\"},\"selection_glyph\":null,\"view\":{\"id\":\"9159\"}},\"id\":\"9158\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"9144\",\"type\":\"ResetTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"wr_mean\"},\"y\":{\"field\":\"wr_imp\"}},\"id\":\"9157\",\"type\":\"Circle\"},{\"attributes\":{\"axis_label\":\"Impact\",\"formatter\":{\"id\":\"9304\"},\"ticker\":{\"id\":\"9137\"}},\"id\":\"9136\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"9128\",\"type\":\"LinearScale\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"9146\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"9304\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"9133\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"9136\"},\"dimension\":1,\"ticker\":null},\"id\":\"9139\",\"type\":\"Grid\"}],\"root_ids\":[\"9121\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
" var render_items = [{\"docid\":\"eeba9fd5-c487-4684-9651-611f36c6df86\",\"root_ids\":[\"9121\"],\"roots\":{\"9121\":\"7047dda4-b5a6-4881-bdd6-37dc7cc95501\"}}];\n",
" root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
"\n",
" }\n",
" if (root.Bokeh !== undefined) {\n",
" embed_document(root);\n",
" } else {\n",
" var attempts = 0;\n",
" var timer = setInterval(function(root) {\n",
" if (root.Bokeh !== undefined) {\n",
" clearInterval(timer);\n",
" embed_document(root);\n",
" } else {\n",
" attempts++;\n",
" if (attempts > 100) {\n",
" clearInterval(timer);\n",
" console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
" }\n",
" }\n",
" }, 10, root)\n",
" }\n",
"})(window);"
],
"application/vnd.bokehjs_exec.v0+json": ""
},
"metadata": {
"application/vnd.bokehjs_exec.v0+json": {
"id": "9121"
}
},
"output_type": "display_data"
}
],
"source": [
"p = figure(title = \"\")\n",
"p.circle('wr_mean','wr_imp',source=water_risk_impact[['wr_mean','wr_imp']][4:],fill_alpha=0.2, size=10)\n",
"p.xaxis.axis_label = 'Risk'\n",
"p.yaxis.axis_label = 'Impact'\n",
"show(p)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7b605108",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}