In [1]:
%config InlineBackend.figure_formats = ['svg']
import oscovida as ov
In [2]:
ov.display_binder_link("tutorial-acessing-population-data.ipynb")

OSCOVIDA Tutorial:

Loading population data for contries and regions

The main function to access population of time is population(). Here are some examples:

In [3]:
ov.population('Argentina')
Out[3]:
45195777

The function has three string arguments:

  • country — mandatory
  • region — optional
  • subregion — optional

The function returns either int value, or None. The latter means the lack of region/subregion support for the existing country.

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:

In [4]:
print(f"Population of Georgia is {ov.population('Georgia')} people")
print(f"To see the state of U.S use 'US, Georgia', its population is {ov.population('US','Georgia')}")
Population of Georgia is 3989175 people
To see the state of U.S use 'US, Georgia', its population is None

You the None value because at the moment region and subregion is only supported for Germany:

In [5]:
print(f"Region: population of Bavaria is {ov.population(country='Germany',region='Bayern')} people")
print(f"Subregion: population of Bonn is {ov.population(country='Germany',subregion='SK Bonn')} people")
print(f"Population of Berlin Mitte is {ov.population('Germany','SK Berlin Mitte')} people")
Region: population of Bavaria is 13124737 people
Subregion: population of Bonn is 329673 people
Population of Berlin Mitte is 375238 people

In the last example one may note two pecularities:

  1. we may use either region or subregion, but not both of them;
  2. for German region and subregions we use additional prefixes LK (Landkreis) or SK (Stadtkreis).

It's easy to find them all just by accidental mistyping:

In [6]:
try:
    ov.population('Germany', 'Hannover')
except NotImplementedError as e:
    print("There will be an exception raised:\n", e)
There will be an exception raised:
 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.

Also, because regions and subregions are unique, you may omit the reference, and algorithm will guess it for you:

In [7]:
bremen = ov.population('Germany', 'Bremen')
luebeck = ov.population('Germany', 'SK Lübeck')
print(f"Bremen ({bremen}) is a region while Lübeck ({luebeck}) is a subregion.")
Bremen (681202) is a region while Lübeck (216530) is a subregion.

Advanced: internals of population

population is a wrapper which calls another functions like get_population or germany_get_population.

In [8]:
# Run this cell to see the source code of the function
ov.population??

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.

In [9]:
ov.get_population()
Out[9]:
UID code3 FIPS Lat Long_ population
Country_Region
Afghanistan 4 4.0 0.0 33.939110 67.709953 38928341.0
Albania 8 8.0 0.0 41.153300 20.168300 2877800.0
Algeria 12 12.0 0.0 28.033900 1.659600 43851043.0
Andorra 20 20.0 0.0 42.506300 1.521800 77265.0
Angola 24 24.0 0.0 -11.202700 17.873900 32866268.0
... ... ... ... ... ... ...
West Bank and Gaza 275 275.0 0.0 31.952200 35.233200 5101416.0
Western Sahara 732 732.0 0.0 24.215500 -12.885800 597330.0
Yemen 887 887.0 0.0 15.552727 48.516388 29825968.0
Zambia 894 894.0 0.0 -13.133897 27.849332 18383956.0
Zimbabwe 716 716.0 0.0 -19.015438 29.154857 14862927.0

189 rows × 6 columns

Other tutorials

You can find more tutorials here.