pycensus.year_built¶
Four year-of-construction shares of dwellings from any source's own construction-period bands.
dwellings_built_before_1945_share, dwellings_built_1945_1970_share, dwellings_built_1970_2000_share, dwellings_built_after_2000_share (0-1).
Bands come from reference/year_built_bands.json (US ACS B25034, Spain Census 2021 / Catastro, Germany Zensus 2022 grid, Canada StatCan 2021). Each band
[first, last] is spread uniformly over its years (half-open [first, last+1)) and cut at the bin edges 1945 / 1970 / 2000, so a band straddling an edge is
split pro rata (ACS 1940-49 -> 50 % before 1945; German 1919-48 -> 26/30 before 1945; Spanish 1961-70 -> 9/10 before 1970); the oldest open band is
assumed to start in 1900. Unknown-year dwellings are not part of the denominator (the shares of the known ones sum to 1).
config()
cached
¶
The year-built configuration (band edges and the sources' band columns).
Returns:
| Type | Description |
|---|---|
dict
|
The config dict. |
band_fractions(first, last, edges=(1945, 1970, 2000), open_start=1900, open_end=2030)
¶
Fraction of the years [first, last] (inclusive) that fall in each of the len(edges)+1 bins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
first
|
Optional[int]
|
First year of the band (None: open start). |
required |
last
|
Optional[int]
|
Last year of the band (None: open end). |
required |
edges
|
Sequence[int]
|
Bin edges. |
(1945, 1970, 2000)
|
open_start
|
int
|
Year used for an open start. |
1900
|
open_end
|
int
|
Year used for an open end. |
2030
|
shares_from_bands(df, columns, scale=1.0)
¶
DataFrame with the four SHARE_NAMES columns (NaN where no band has data); scale 100 gives percentages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
Table with band columns. |
required | |
columns
|
Dict[str, Sequence[Optional[int]]]
|
|
required |
scale
|
float
|
1 for shares, 100 for percentages. |
1.0
|
pick_source(columns)
¶
The first configured source with at least one band column in columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
Column names. |
required |
add_year_built_shares(df, scale=None)
¶
Add the four share columns to df (in place) from the first source whose band columns are present; no-op when none or already present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
Table. |
required | |
scale
|
Optional[float]
|
1 or 100; |
None
|
Returns:
| Type | Description |
|---|---|
|
The same table. |
drop_intermediate_bands(df)
¶
df without the raw band columns of intermediate sources once the four shares exist (map inputs only).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
Table. |
required |