pycensuskr
A Python package for Korean district-level census and geographic data.
Installation
PyPI
pip install pycensuskr
From source
git clone https://github.com/sigmafelix/pycensuskr.git
cd pycensuskr
pip install -e .
# python setup.py install
For development
git clone https://github.com/sigmafelix/pycensuskr.git
cd pycensuskr
pip install -e ".[dev]"
Usage
from pycensuskr import CensusKR
from matplotlib import pyplot as plt
import geopandas as gpd
# Create a CensusData instance
census = CensusKR()
# load specific year data
data_2020 = census.load_data(year = 2020)
print(data_2020)
# load district boundaries for a specific year
districts_2020 = census.load_districts(year = 2020)
districts_2020["adm2_re"] = districts_2020["adm2_code"].astype(str).str.slice(0,4)
# aggregate geometries by adm2_re
districts_2020 = districts_2020.dissolve(by="adm2_re", as_index=False)
districts_2020["adm2_code"] = districts_2020["adm2_re"] + "0"
districts_2020["adm2_code"] = districts_2020["adm2_code"].astype(int)
# cleaned data with variable types
df_tax_2020 = census.anycensus(year = 2020, type = "tax", aggregator = "sum")
districts_tax_2020 = districts_2020.merge(df_tax_2020, on="adm2_code")
print(districts_tax_2020)
districts_tax_2020.plot("income_labor_mil")
plt.show()
Filter non-/autonomous district codes
For overlapping city and district observations, anycensus(adm2_type="all")
excludes the city count for each indicator with district values while retaining
city and district rates. "atn" sums available district counts into the city
and keeps its rate unless weights are supplied; "non" returns district rows.
Incomplete district sums produce a warning.
Parent and non-autonomous district codes are compared separately for each
year when the input contains a year column.
from pycensuskr import CensusKR
# Create a CensusData instance
census = CensusKR()
# load population data
pop20 = census.anycensus(year=2020, type="population")
pop20_nonauto = census.detect_adm2_type(df=pop20, mode="non")
Load adm3-level data
- ADM3 (Eup/Myeon/Dong) boundaries are available through 2025. ADM3 population and housing data is available for 2015, 2020, and 2025; economy and mortality ADM3 data is available for 2020.
ADM2 boundaries are available for 2010, 2015, 2020, and 2025. The 2025 ADM2 layer is based on KOSTAT's 2025 second-quarter boundary file, reference date 2025-06-30.
from pycensuskr import CensusKR
# Create a CensusData instance
census = CensusKR()
# load population data
pop20_adm3 = census.anycensus(year = 2020, type = "population", level = "adm3")
# load housing data
housing20_adm3 = census.anycensus(year = 2020, type = "housing", level = "adm3")
# load 2025 neighborhood-level housing data (tabular; no 2025 boundaries are bundled)
housing25_adm3 = census.anycensus(year = 2025, type = "housing", level = "adm3")
Notes on data updates
Our data cleaning and processing pipeline is based on the original R package tidycensuskr. We periodically synchronize the bundled datasets used in this package with those in R tidycensuskr and tidycensuskr.sf to ensure accuracy and relevance. Please refer to the tidycensuskr webpage for details on the latest data updates and changes.
Data license disclaimer
- The data is provided under the Korea Open Government License Type 1 (Attribution) (Note: in Korean). Each raw data table is available for download from the Public Data Portal and KOSIS with no cost.
{style="fig-align: center; width: 200px;"}
Development
Running tests
pytest
License
This project is licensed under the MIT License - see the LICENSE file for details.
Supplemental spatial weights
Binary NumPy arrays w_mat_YYYY.npy (Queen plus marine road bridges/subsea
tunnels open by December 31) and w_mat_o_YYYY.npy (Queen only) are bundled
for 2010, 2015, 2020 and 2025. Load with numpy.load(..., allow_pickle=False);
the matching *_order.json gives the exact adm2_code_order. Always align
observations by these codes; arrays have zero diagonals and are not row
standardized. Shapes are 251, 252, 250 and 252 square, respectively.
The boundary GeoPackage is distributed as pycensuskr/data/boundaries.gpkg.xz.
load_districts() unpacks it to a temporary directory for each call; to use the
GeoPackage directly in other software, decompress the .xz file first.
All four ADM2 GeoPackage layers use the validated tidycensuskr boundaries,
with the original fields and row order retained. 2010/2015 overlapping faces
were repaired using their own boundary networks; the 2020 repair uses 2015
historical evidence and 2020 geometry. 2025 contacts match its same-year raw
source.
See the executed Moran's I example
for code alignment, libpysal conversion, and a reproducible permutation test.
Install its optional dependencies with pip install libpysal esda nbformat nbclient ipykernel.
Metadata
Release files for pycensuskr 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pycensuskr-0.4.2.tar.gz | 29.3 MB | With provenance | Details for pycensuskr-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pycensuskr-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for pycensuskr-0.4.2-py3-none-any.whl |
Total release size: 58.5 MB
Release files / pycensuskr-0.4.2.tar.gz
| Download URL | pycensuskr-0.4.2.tar.gz |
|---|---|
| Size | 29.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30ee72749b32b8d48cf6d83011ba39e47df9b184b7a322ffeaf394eb327a374d
|
|
BLAKE2b-256 checksum How to use checksums |
461d9e3d216d297da2e26f1f02c9a0fff7310afd4d3e041581e3eee38edf3296
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / pycensuskr-0.4.2-py3-none-any.whl
| Download URL | pycensuskr-0.4.2-py3-none-any.whl |
|---|---|
| Size | 29.3 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8642ea5b80490dd3d9d71c56d8d25f111a994a7db4510e892e158b8068b5a1a5
|
|
BLAKE2b-256 checksum How to use checksums |
cd7875133342cd2eb78df72f89c3c4eff4de2324b65a759b038d8752b39a5b32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logSecurity for pycensuskr 0.4.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pycensuskr-0.4.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.