{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%config InlineBackend.figure_formats = ['svg']\n", "import oscovida as ov" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": "", "text/markdown": "[Execute this notebook with Binder](https://mybinder.org/v2/gh/oscovida/binder/master?filepath=ipynb/tutorial-acessing-population-data.ipynb)" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "ov.display_binder_link(\"tutorial-acessing-population-data.ipynb\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## OSCOVIDA Tutorial:\n", "### Loading population data for contries and regions\n", "\n", "The main function to access population of time is `population()`. Here are some examples:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": "45195777" }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ov.population('Argentina')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The function has three string arguments: \n", "* `country` — mandatory\n", "* `region` — optional\n", "* `subregion` — optional\n", "\n", "The function returns either `int` value, or `None`. The latter means the lack of region/subregion support for the existing country.\n", "\n", "If you pass only one argument without additional explanation, it will be considered as `country`. The next argument will be treated as `region`, however you may point out that you mean `subregion`:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Population of Georgia is 3989175 people\n", "To see the state of U.S use 'US, Georgia', its population is None\n" ] } ], "source": [ "print(f\"Population of Georgia is {ov.population('Georgia')} people\")\n", "print(f\"To see the state of U.S use 'US, Georgia', its population is {ov.population('US','Georgia')}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You the `None` value because at the moment `region` and `subregion` is only supported for Germany:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Region: population of Bavaria is 13124737 people\n", "Subregion: population of Bonn is 329673 people\n", "Population of Berlin Mitte is 375238 people\n" ] } ], "source": [ "print(f\"Region: population of Bavaria is {ov.population(country='Germany',region='Bayern')} people\")\n", "print(f\"Subregion: population of Bonn is {ov.population(country='Germany',subregion='SK Bonn')} people\")\n", "print(f\"Population of Berlin Mitte is {ov.population('Germany','SK Berlin Mitte')} people\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the last example one may note two pecularities:\n", "1. we may use either `region` or `subregion`, but not both of them;\n", "2. for German region and subregions we use additional prefixes `LK` (*Landkreis*) or `SK` (*Stadtkreis*).\n", "\n", "It's easy to find them all just by accidental mistyping:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There will be an exception raised:\n", " Hannover in neither in available German Lands nor in Landkreises. These are Baden-Württemberg, Bayern, Berlin, Brandenburg, Bremen, Hamburg, Hessen, Mecklenburg-Vorpommern, Niedersachsen, Nordrhein-Westfalen, Rheinland-Pfalz, Saarland, Sachsen, Sachsen-Anhalt, Schleswig-Holstein, Thüringen for Lands and LK Ahrweiler, LK Aichach-Friedberg, LK Alb-Donau-Kreis, LK Altenburger Land, LK Altenkirchen, LK Altmarkkreis Salzwedel, LK Altötting, LK Alzey-Worms, LK Amberg-Sulzbach, LK Ammerland, LK Anhalt-Bitterfeld, LK Ansbach, LK Aschaffenburg, LK Augsburg, LK Aurich, LK Bad Dürkheim, LK Bad Kissingen, LK Bad Kreuznach, LK Bad Tölz-Wolfratshausen, LK Bamberg, LK Barnim, LK Bautzen, LK Bayreuth, LK Berchtesgadener Land, LK Bergstraße, LK Bernkastel-Wittlich, LK Biberach, LK Birkenfeld, LK Bitburg-Prüm, LK Bodenseekreis, LK Borken, LK Breisgau-Hochschwarzwald, LK Burgenlandkreis, LK Böblingen, LK Börde, LK Calw, LK Celle, LK Cham, LK Cloppenburg, LK Coburg, LK Cochem-Zell, LK Coesfeld, LK Cuxhaven, LK Dachau, LK Dahme-Spreewald, LK Darmstadt-Dieburg, LK Deggendorf, LK Diepholz, LK Dillingen a.d.Donau, LK Dingolfing-Landau, LK Dithmarschen, LK Donau-Ries, LK Donnersbergkreis, LK Düren, LK Ebersberg, LK Eichsfeld, LK Eichstätt, LK Elbe-Elster, LK Emmendingen, LK Emsland, LK Ennepe-Ruhr-Kreis, LK Enzkreis, LK Erding, LK Erlangen-Höchstadt, LK Erzgebirgskreis, LK Esslingen, LK Euskirchen, LK Forchheim, LK Freising, LK Freudenstadt, LK Freyung-Grafenau, LK Friesland, LK Fulda, LK Fürstenfeldbruck, LK Fürth, LK Garmisch-Partenkirchen, LK Germersheim, LK Gießen, LK Gifhorn, LK Goslar, LK Gotha, LK Grafschaft Bentheim, LK Greiz, LK Groß-Gerau, LK Göppingen, LK Görlitz, LK Göttingen, LK Günzburg, LK Gütersloh, LK Hameln-Pyrmont, LK Harburg, LK Harz, LK Havelland, LK Haßberge, LK Heidekreis, LK Heidenheim, LK Heilbronn, LK Heinsberg, LK Helmstedt, LK Herford, LK Hersfeld-Rotenburg, LK Herzogtum Lauenburg, LK Hildburghausen, LK Hildesheim, LK Hochsauerlandkreis, LK Hochtaunuskreis, LK Hof, LK Hohenlohekreis, LK Holzminden, LK Höxter, LK Ilm-Kreis, LK Jerichower Land, LK Kaiserslautern, LK Karlsruhe, LK Kassel, LK Kelheim, LK Kitzingen, LK Kleve, LK Konstanz, LK Kronach, LK Kulmbach, LK Kusel, LK Kyffhäuserkreis, LK Lahn-Dill-Kreis, LK Landsberg a.Lech, LK Landshut, LK Leer, LK Leipzig, LK Lichtenfels, LK Limburg-Weilburg, LK Lindau, LK Lippe, LK Ludwigsburg, LK Ludwigslust-Parchim, LK Lörrach, LK Lüchow-Dannenberg, LK Lüneburg, LK Main-Kinzig-Kreis, LK Main-Spessart, LK Main-Tauber-Kreis, LK Main-Taunus-Kreis, LK Mainz-Bingen, LK Mansfeld-Südharz, LK Marburg-Biedenkopf, LK Mayen-Koblenz, LK Mecklenburgische Seenplatte, LK Meißen, LK Merzig-Wadern, LK Mettmann, LK Miesbach, LK Miltenberg, LK Minden-Lübbecke, LK Mittelsachsen, LK Märkisch-Oderland, LK Märkischer Kreis, LK Mühldorf a.Inn, LK München, LK Neckar-Odenwald-Kreis, LK Neu-Ulm, LK Neuburg-Schrobenhausen, LK Neumarkt i.d.OPf., LK Neunkirchen, LK Neustadt a.d.Aisch-Bad Windsheim, LK Neustadt a.d.Waldnaab, LK Neuwied, LK Nienburg (Weser), LK Nordfriesland, LK Nordhausen, LK Nordsachsen, LK Nordwestmecklenburg, LK Northeim, LK Nürnberger Land, LK Oberallgäu, LK Oberbergischer Kreis, LK Oberhavel, LK Oberspreewald-Lausitz, LK Odenwaldkreis, LK Oder-Spree, LK Offenbach, LK Oldenburg, LK Olpe, LK Ortenaukreis, LK Osnabrück, LK Ostalbkreis, LK Ostallgäu, LK Osterholz, LK Ostholstein, LK Ostprignitz-Ruppin, LK Paderborn, LK Passau, LK Peine, LK Pfaffenhofen a.d.Ilm, LK Pinneberg, LK Plön, LK Potsdam-Mittelmark, LK Prignitz, LK Rastatt, LK Ravensburg, LK Recklinghausen, LK Regen, LK Regensburg, LK Rems-Murr-Kreis, LK Rendsburg-Eckernförde, LK Reutlingen, LK Rhein-Erft-Kreis, LK Rhein-Hunsrück-Kreis, LK Rhein-Kreis Neuss, LK Rhein-Lahn-Kreis, LK Rhein-Neckar-Kreis, LK Rhein-Pfalz-Kreis, LK Rhein-Sieg-Kreis, LK Rheingau-Taunus-Kreis, LK Rheinisch-Bergischer Kreis, LK Rhön-Grabfeld, LK Rosenheim, LK Rostock, LK Rotenburg (Wümme), LK Roth, LK Rottal-Inn, LK Rottweil, LK Saale-Holzland-Kreis, LK Saale-Orla-Kreis, LK Saalekreis, LK Saalfeld-Rudolstadt, LK Saar-Pfalz-Kreis, LK Saarlouis, LK Salzlandkreis, LK Sankt Wendel, LK Schaumburg, LK Schleswig-Flensburg, LK Schmalkalden-Meiningen, LK Schwalm-Eder-Kreis, LK Schwandorf, LK Schwarzwald-Baar-Kreis, LK Schweinfurt, LK Schwäbisch Hall, LK Segeberg, LK Siegen-Wittgenstein, LK Sigmaringen, LK Soest, LK Sonneberg, LK Spree-Neiße, LK Stade, LK Stadtverband Saarbrücken, LK Starnberg, LK Steinburg, LK Steinfurt, LK Stendal, LK Stormarn, LK Straubing-Bogen, LK Sächsische Schweiz-Osterzgebirge, LK Sömmerda, LK Südliche Weinstraße, LK Südwestpfalz, LK Teltow-Fläming, LK Tirschenreuth, LK Traunstein, LK Trier-Saarburg, LK Tuttlingen, LK Tübingen, LK Uckermark, LK Uelzen, LK Unna, LK Unstrut-Hainich-Kreis, LK Unterallgäu, LK Vechta, LK Verden, LK Viersen, LK Vogelsbergkreis, LK Vogtlandkreis, LK Vorpommern-Greifswald, LK Vorpommern-Rügen, LK Vulkaneifel, LK Waldeck-Frankenberg, LK Waldshut, LK Warendorf, LK Wartburgkreis, LK Weilheim-Schongau, LK Weimarer Land, LK Weißenburg-Gunzenhausen, LK Werra-Meißner-Kreis, LK Wesel, LK Wesermarsch, LK Westerwaldkreis, LK Wetteraukreis, LK Wittenberg, LK Wittmund, LK Wolfenbüttel, LK Wunsiedel i.Fichtelgebirge, LK Würzburg, LK Zollernalbkreis, LK Zwickau, Region Hannover, SK Amberg, SK Ansbach, SK Aschaffenburg, SK Augsburg, SK Baden-Baden, SK Bamberg, SK Bayreuth, SK Berlin Charlottenburg-Wilmersdorf, SK Berlin Friedrichshain-Kreuzberg, SK Berlin Lichtenberg, SK Berlin Marzahn-Hellersdorf, SK Berlin Mitte, SK Berlin Neukölln, SK Berlin Pankow, SK Berlin Reinickendorf, SK Berlin Spandau, SK Berlin Steglitz-Zehlendorf, SK Berlin Tempelhof-Schöneberg, SK Berlin Treptow-Köpenick, SK Bielefeld, SK Bochum, SK Bonn, SK Bottrop, SK Brandenburg a.d.Havel, SK Braunschweig, SK Bremen, SK Bremerhaven, SK Chemnitz, SK Coburg, SK Cottbus, SK Darmstadt, SK Delmenhorst, SK Dessau-Roßlau, SK Dortmund, SK Dresden, SK Duisburg, SK Düsseldorf, SK Eisenach, SK Emden, SK Erfurt, SK Erlangen, SK Essen, SK Flensburg, SK Frankenthal, SK Frankfurt (Oder), SK Frankfurt am Main, SK Freiburg i.Breisgau, SK Fürth, SK Gelsenkirchen, SK Gera, SK Hagen, SK Halle, SK Hamburg, SK Hamm, SK Heidelberg, SK Heilbronn, SK Herne, SK Hof, SK Ingolstadt, SK Jena, SK Kaiserslautern, SK Karlsruhe, SK Kassel, SK Kaufbeuren, SK Kempten, SK Kiel, SK Koblenz, SK Krefeld, SK Köln, SK Landau i.d.Pfalz, SK Landshut, SK Leipzig, SK Leverkusen, SK Ludwigshafen, SK Lübeck, SK Magdeburg, SK Mainz, SK Mannheim, SK Memmingen, SK Mönchengladbach, SK Mülheim a.d.Ruhr, SK München, SK Münster, SK Neumünster, SK Neustadt a.d.Weinstraße, SK Nürnberg, SK Oberhausen, SK Offenbach, SK Oldenburg, SK Osnabrück, SK Passau, SK Pforzheim, SK Pirmasens, SK Potsdam, SK Regensburg, SK Remscheid, SK Rosenheim, SK Rostock, SK Salzgitter, SK Schwabach, SK Schweinfurt, SK Schwerin, SK Solingen, SK Speyer, SK Straubing, SK Stuttgart, SK Suhl, SK Trier, SK Ulm, SK Weiden i.d.OPf., SK Weimar, SK Wiesbaden, SK Wilhelmshaven, SK Wolfsburg, SK Worms, SK Wuppertal, SK Würzburg, SK Zweibrücken, StadtRegion Aachen for Landkreises.\n" ] } ], "source": [ "try:\n", " ov.population('Germany', 'Hannover')\n", "except NotImplementedError as e:\n", " print(\"There will be an exception raised:\\n\", e)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Also, because `region`s and `subregion`s are unique, you may omit the reference, and algorithm will guess it for you:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Bremen (681202) is a region while Lübeck (216530) is a subregion.\n" ] } ], "source": [ "bremen = ov.population('Germany', 'Bremen')\n", "luebeck = ov.population('Germany', 'SK Lübeck')\n", "print(f\"Bremen ({bremen}) is a region while Lübeck ({luebeck}) is a subregion.\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Advanced: internals of `population`\n", "`population` is a wrapper which calls another functions like `get_population` or `germany_get_population`." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# Run this cell to see the source code of the function\n", "ov.population??" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In turn, `get_population` function actually fetches all data and returns Pandas Series. Then `population` reduces the amount of data to the particular country data. It also does provides some niceties like guessing if the user wants a region or a subregion." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": " UID code3 FIPS Lat Long_ population\nCountry_Region \nAfghanistan 4 4.0 0.0 33.939110 67.709953 38928341.0\nAlbania 8 8.0 0.0 41.153300 20.168300 2877800.0\nAlgeria 12 12.0 0.0 28.033900 1.659600 43851043.0\nAndorra 20 20.0 0.0 42.506300 1.521800 77265.0\nAngola 24 24.0 0.0 -11.202700 17.873900 32866268.0\n... ... ... ... ... ... ...\nWest Bank and Gaza 275 275.0 0.0 31.952200 35.233200 5101416.0\nWestern Sahara 732 732.0 0.0 24.215500 -12.885800 597330.0\nYemen 887 887.0 0.0 15.552727 48.516388 29825968.0\nZambia 894 894.0 0.0 -13.133897 27.849332 18383956.0\nZimbabwe 716 716.0 0.0 -19.015438 29.154857 14862927.0\n\n[189 rows x 6 columns]", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
UIDcode3FIPSLatLong_population
Country_Region
Afghanistan44.00.033.93911067.70995338928341.0
Albania88.00.041.15330020.1683002877800.0
Algeria1212.00.028.0339001.65960043851043.0
Andorra2020.00.042.5063001.52180077265.0
Angola2424.00.0-11.20270017.87390032866268.0
.....................
West Bank and Gaza275275.00.031.95220035.2332005101416.0
Western Sahara732732.00.024.215500-12.885800597330.0
Yemen887887.00.015.55272748.51638829825968.0
Zambia894894.00.0-13.13389727.84933218383956.0
Zimbabwe716716.00.0-19.01543829.15485714862927.0
\n

189 rows × 6 columns

\n
" }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ov.get_population()" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "## Other tutorials\n", "\n", "You can [find more tutorials here](tag-tutorial.html)." ] } ], "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.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }