コード例 #1
0
 def test_load_countries(self):
     db = mundi.countries()
     assert len(db) == 255
コード例 #2
0
 def countries(self):
     return mundi.countries(["br", "it", "cn"])
コード例 #3
0
 def db(self):
     db = mundi.countries()
     return db.iloc[:10]
コード例 #4
0
# POP/DB/WPP/Rev.2019/POP/F15-1
#
# © August 2019 by United Nations, made available under a Creative Commons license CC
# BY 3.0 IGO: http://creativecommons.org/licenses/by/3.0/igo/
# Suggested citation: United Nations, Department of Economic and Social Affairs,
# Population Division (2019). World Population Prospects 2019, Online Edition. Rev. 1.
#
from pathlib import Path

import pandas as pd

import mundi

PATH = Path(__file__).parent.resolve()

countries = mundi.countries()
code_map = (countries.mundi["short_code", "numeric_code"].set_index(
    "numeric_code")["short_code"].to_dict())

# Read raw data and transform a few columns
data = pd.read_csv(PATH / "age-distribution.csv.gz").astype({"year": "int32"})
data["code"] = data["code"].apply(lambda x: f"{x:03}")
data["id"] = data["code"].apply(code_map.get)

# Channel Islands is not present in the Mundi database.
# TODO: investigate it. Is Pycountry using an old ISO standard? Is it not
# registered in ISO? Is is just a weird geographical denomination?
removed = set(data[data["id"].isna()]["name"])
print(f"WARNING: removed items {removed}")

# Reorganize data
コード例 #5
0
ファイル: utils.py プロジェクト: GCES-Pydemic/pydemic
def world_age_distribution():
    """
    World age distribution computed by summing
    """
    countries = mundi.countries()
    return countries.mundi["age_distribution"].sum(0)