Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Utility Tools for Population Estimates

Project description

estpop is a Python package providing population forecasting from historical data. This method is based on cohort change ratio[1].

Sample Code

Change Ratio

import numpy as np
import openpyxl
import estpop

sheet = openpyxl.load_workbook('data.xlsx').worksheets[0]

pops = {}
for i in range(1, sheet.max_row):
    code = sheet.cell(i+1, 3).value

    if not code in pops:
        pops[code] = []

    males, females = [], []
    for j in range(29, 50):
        males.append(sheet.cell(i+1, j).value)
        females.append(sheet.cell(i+1, j+22).value)
    pops[code].append([males, females])

ratios = {}
for k, v in pops.items():
    change_ratios, baby_ratios, tail_ratios = [], [], []
        for i in range(len(v) - 5):
            change_ratio, baby_ratio, tail_ratio = estpop.ratios(v[i], v[i+5])

        ratios[k] = {
            'change_ratio': np.mean(change_ratios, axis=0).tolist(),
            'baby_ratio': float(np.mean(baby_ratios)),
            'tail_ratio': float(np.mean(tail_ratios))


import openpyxl
import estpop

f = open('result.csv', mode='w')

for k, v in pops.items():
    if k in [411, 421, 521]:
        change_ratio = ratios[0]['change_ratio']
        baby_ratio = ratios[0]['baby_ratio']
        tail_ratio = ratios[0]['tail_ratio']
        change_ratio = ratios[k]['change_ratio']
        baby_ratio = ratios[k]['baby_ratio']
        tail_ratio = ratios[k]['tail_ratio']

        year = 2020
        estimates = v[5]

        for i in range(7):
            estimates = estpop.simulate(estimates, change_ratio,
                                        baby_ratio, tail_ratio)
            f.write('%s,%s,%s,%s\n' % (k, year+i*5,
                                       ','.join(map(str, estimates[0])),
                                       ','.join(map(str, estimates[1]))))



  1. Einoshin SUZUKI, Kaoru MORI, Koichi NAGASE, Masatoshi TAMAMURA, Ikuyo KANEKO: The Development of the Future Predictive Model of 'Potentially Disappearing Neighborhood Associations' Using Demographic Data of the Neighborhood Association Base, Journal of the Japan Association of Regional Development and Vitalization, Vol.6, pp.20-30, 2015.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for estpop, version 0.0.4
Filename, size File type Python version Upload date Hashes
Filename, size estpop-0.0.4-py3-none-any.whl (3.7 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page