-
Notifications
You must be signed in to change notification settings - Fork 7
/
example_extrapolate_all.py
31 lines (22 loc) · 816 Bytes
/
example_extrapolate_all.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pandas as pd
import ukpopulation.nppdata as NPPData
import ukpopulation.snppdata as SNPPData
import ukpopulation.utils as utils
# initialise the population modules
npp = NPPData.NPPData()
snpp = SNPPData.SNPPData()
# start with an empty data frame
result = pd.DataFrame()
country = utils.WA
horizon = 2050
# get the first year where extrapolation is necessary, extrapolate to 2050
ex_years = range(snpp.max_year(country) + 1, horizon + 1)
# loop over all the Welsh LADs
for lad in snpp.data[country].GEOGRAPHY_CODE.unique():
print(lad)
# extrapolate and aggregate
lad = snpp.extrapolagg(["GENDER", "C_AGE"], npp, lad, ex_years)
# append to data
result = result.append(lad, ignore_index=True)
# write out results
result.to_csv("snpp_extrap_{}_{}.csv".format(country, horizon), index=False)