|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# One Queue or Two" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": 2, |
| 13 | + "metadata": { |
| 14 | + "tags": [] |
| 15 | + }, |
| 16 | + "outputs": [], |
| 17 | + "source": [ |
| 18 | + "# download modsim.py if necessary\n", |
| 19 | + "\n", |
| 20 | + "from os.path import basename, exists\n", |
| 21 | + "\n", |
| 22 | + "def download(url):\n", |
| 23 | + " filename = basename(url)\n", |
| 24 | + " if not exists(filename):\n", |
| 25 | + " from urllib.request import urlretrieve\n", |
| 26 | + " local, _ = urlretrieve(url, filename)\n", |
| 27 | + " print('Downloaded ' + local)\n", |
| 28 | + " \n", |
| 29 | + "download('https://raw.githubusercontent.com/AllenDowney/' +\n", |
| 30 | + " 'ModSimPy/master/data/World_population_estimates.html')" |
| 31 | + ] |
| 32 | + }, |
| 33 | + { |
| 34 | + "cell_type": "code", |
| 35 | + "execution_count": 13, |
| 36 | + "metadata": {}, |
| 37 | + "outputs": [], |
| 38 | + "source": [ |
| 39 | + "%load_ext nb_black" |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + "cell_type": "code", |
| 44 | + "execution_count": 12, |
| 45 | + "metadata": {}, |
| 46 | + "outputs": [], |
| 47 | + "source": [ |
| 48 | + "import pandas as pd\n", |
| 49 | + "import requests\n", |
| 50 | + "\n", |
| 51 | + "# Fetch the data.\n", |
| 52 | + "df = pd.read_csv(\"https://ourworldindata.org/grapher/population.csv?v=1&csvType=filtered&useColumnShortNames=true&time=1700..latest&country=~OWID_WRL\", storage_options = {'User-Agent': 'Our World In Data data fetch/1.0'})\n", |
| 53 | + "\n", |
| 54 | + "# Fetch the metadata\n", |
| 55 | + "metadata = requests.get(\"https://ourworldindata.org/grapher/population.metadata.json?v=1&csvType=filtered&useColumnShortNames=true&time=1700..latest&country=~OWID_WRL\").json()" |
| 56 | + ] |
| 57 | + }, |
| 58 | + { |
| 59 | + "cell_type": "code", |
| 60 | + "execution_count": 9, |
| 61 | + "metadata": {}, |
| 62 | + "outputs": [], |
| 63 | + "source": [ |
| 64 | + "table2.loc[1950:1980].plot()" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "cell_type": "markdown", |
| 69 | + "metadata": {}, |
| 70 | + "source": [ |
| 71 | + "*Modeling and Simulation in Python*\n", |
| 72 | + "\n", |
| 73 | + "Copyright 2021 Allen Downey\n", |
| 74 | + "\n", |
| 75 | + "License: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "code", |
| 80 | + "execution_count": null, |
| 81 | + "metadata": {}, |
| 82 | + "outputs": [], |
| 83 | + "source": [] |
| 84 | + } |
| 85 | + ], |
| 86 | + "metadata": { |
| 87 | + "celltoolbar": "Tags", |
| 88 | + "kernelspec": { |
| 89 | + "display_name": "Python 3 (ipykernel)", |
| 90 | + "language": "python", |
| 91 | + "name": "python3" |
| 92 | + }, |
| 93 | + "language_info": { |
| 94 | + "codemirror_mode": { |
| 95 | + "name": "ipython", |
| 96 | + "version": 3 |
| 97 | + }, |
| 98 | + "file_extension": ".py", |
| 99 | + "mimetype": "text/x-python", |
| 100 | + "name": "python", |
| 101 | + "nbconvert_exporter": "python", |
| 102 | + "pygments_lexer": "ipython3", |
| 103 | + "version": "3.10.13" |
| 104 | + } |
| 105 | + }, |
| 106 | + "nbformat": 4, |
| 107 | + "nbformat_minor": 2 |
| 108 | +} |
0 commit comments