{ "cells": [ { "cell_type": "markdown", "id": "d0e86abf-b283-475d-89a6-d4ba5f8d7c2b", "metadata": {}, "source": [ "# Exploring GeoPandas: Natural Earth Low Res Data Set\n", "This `JupyterLab` notebook is soley for exploring `GeoPandas` using the builtin data: `naturalearth_lowres`." ] }, { "cell_type": "markdown", "id": "2b189141-3d74-4731-af82-954448d35321", "metadata": {}, "source": [ "## Setup\n", "First let's load the necessary *modules* and *data*." ] }, { "cell_type": "code", "execution_count": null, "id": "00e31f7b-a637-427f-8249-7553f8c1f12b", "metadata": {}, "outputs": [], "source": [ "# first let's get the libs\n", "import geopandas\n", "\n", "# get the earth data\n", "earth_lr = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))\n", "\n", "# see whats in the data\n", "earth_lr" ] }, { "cell_type": "code", "execution_count": null, "id": "1f53e07d-4bea-448b-91e8-167e6fc15d43", "metadata": {}, "outputs": [], "source": [ "# let's see what unique continents are present\n", "CONTINENTS_SET = set(earth_lr['continent'].values)\n", "\n", "# remove some data\n", "CONTINENTS_SET.remove('Seven seas (open ocean)')" ] }, { "cell_type": "markdown", "id": "94e3012b-a5d5-4743-b026-0f83e8ce363b", "metadata": {}, "source": [ "## Natural Earth Lowres: Population Estimate\n", "We will begin exploring this data by looking at the `pop_est` column." ] }, { "cell_type": "code", "execution_count": null, "id": "83aac067-4be4-4d57-b369-db1db32063ce", "metadata": {}, "outputs": [], "source": [ "# first let's look at the entire world's populations\n", "earth_lr.plot('pop_est',\n", " legend=True,\n", " legend_kwds={'label': \"Population by Country\",\n", " 'orientation': \"horizontal\"},\n", " figsize=(16, 16));" ] }, { "cell_type": "code", "execution_count": null, "id": "b3ce1d25-5fdb-4365-bcda-2b0032ef7d49", "metadata": {}, "outputs": [], "source": [ "# next plot all continent Population Estimates separately\n", "for continent in CONTINENTS_SET:\n", " # plot\n", " earth_lr[earth_lr['continent'] == continent].plot('pop_est',\n", " figsize=(16, 12),\n", " legend=True,\n", " legend_kwds={'label': \"Population by Country\",\n", " 'orientation': \"horizontal\"});" ] }, { "cell_type": "markdown", "id": "775dcacb-fc3e-42c4-a0e7-bff17bb331ca", "metadata": {}, "source": [ "## Natural Earth Lowres: GDP Estimate\n", "Next we will be looking at the `gdp_md_est` column." ] }, { "cell_type": "code", "execution_count": null, "id": "ca7137f0-41a7-40c6-a2f8-a7da894c4d58", "metadata": {}, "outputs": [], "source": [ "# first let's look at the entire world's gdp\n", "earth_lr.plot('gdp_md_est',\n", " figsize=(16, 16),\n", " legend=True,\n", " legend_kwds={'label': \"GDP by Country\",\n", " 'orientation': \"horizontal\"});" ] }, { "cell_type": "code", "execution_count": null, "id": "794100dd-2dd7-4c9f-9f04-2c3a957c002a", "metadata": {}, "outputs": [], "source": [ "# plot all continent GDP Estimates\n", "for continent in CONTINENTS_SET:\n", " # plot\n", " earth_lr[earth_lr['continent'] == continent].plot('gdp_md_est',\n", " figsize=(16, 12),\n", " legend=True,\n", " legend_kwds={'label': \"GDP by Country\",\n", " 'orientation': \"horizontal\"});" ] }, { "cell_type": "markdown", "id": "8907ddb4-f6c7-4468-aa4e-ba4517150214", "metadata": {}, "source": [ "## Natural Earth Lowres: Per Capita GDP\n", "Finally we will calculate *per capita GDP* by finding the ration of: \n", "$$\n", "\\frac{GDP}{Population}\n", "$$" ] }, { "cell_type": "code", "execution_count": null, "id": "4ffdfb78-f940-4cae-94b6-84de9b398a83", "metadata": {}, "outputs": [], "source": [ "# calc per capita gdp\n", "earth_lr['per_capita_gdp'] = earth_lr['gdp_md_est'] / earth_lr['pop_est']\n", "\n", "# first let's look at the entire world's per capita gdp\n", "earth_lr.plot('per_capita_gdp', \n", " legend=True, \n", " figsize=(16, 16),\n", " legend_kwds={'label': \"Per Capita GDP by Country\",\n", " 'orientation': \"horizontal\"});" ] }, { "cell_type": "code", "execution_count": null, "id": "3cac121c-a148-4055-8a27-2ae98cbd1b34", "metadata": {}, "outputs": [], "source": [ "# plot all continent Population Estimates\n", "for continent in CONTINENTS_SET:\n", " # plot\n", " earth_lr[earth_lr['continent'] == continent].plot('per_capita_gdp', \n", " figsize=(16, 12),\n", " legend=True,\n", " legend_kwds={'label': \"Per Capita GDP by Country\",\n", " 'orientation': \"horizontal\"});" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.6" } }, "nbformat": 4, "nbformat_minor": 5 }