In [1]:
%config InlineBackend.figure_formats = ['svg']
import oscovida as ov

In [2]:
ov.display_binder_link("tutorial-acessing-population-data.ipynb")


## OSCOVIDA Tutorial:¶

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:


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.