tlf-census-stats
Census-specific statistical analysis for South and Southeast Asian countries — part of TLF ("The Living Facts").
Loads census data (CSV, Excel, or JSON) for a given country, normalizes it to a canonical schema via per-country column aliasing, and produces national totals, descriptive statistics, region-level aggregation, rankings, outlier detection, and HTML/PDF/CSV/JSON reports — either as a library or an interactive CLI.
Supports: Nepal, India, Bangladesh, Pakistan, Sri Lanka, Bhutan.
Install
pip install tlf-census-stats
Or from source, inside the TLF-Data-Analysis monorepo:
cd tlf-census-stats
pip install -e ".[dev]"
Canonical schema
Every country profile maps its own raw column names (e.g. Bangladesh's Division/District, Nepal's Province/District) onto this canonical shape:
| Column | Required? | Notes |
|---|---|---|
region |
Yes | e.g. Division/Province/State |
subregion |
Yes | e.g. District |
total_population |
Yes | |
male |
Yes | |
female |
Yes | |
households |
Yes | |
urban_population |
Optional | |
rural_population |
Optional | |
literacy_rate |
Optional | |
avg_household_size |
Optional | |
third_gender |
Optional | A country's non-binary census category (e.g. Bangladesh's "Hijra"). Not every country publishes this. |
A column-check is printed on every load, showing what was actually found vs. expected for that country.
Quickstart (Python API)
from tlf_census_stats import CensusLoader, StatsReporter
# Load and inspect
df = CensusLoader("bangladesh_census.xlsx", country="bangladesh").load()
# Or run the full report pipeline directly
reporter = StatsReporter("bangladesh_census.xlsx", country="bangladesh")
reporter.run() # prints national totals, descriptive
# stats, region summary, rankings, outliers
reporter.export("report.html") # or .csv / .json / .pdf — same content either way
Reading multiple Excel sheets
# Default: read every sheet, stack their rows into one DataFrame
df = CensusLoader("census.xlsx", country="bangladesh").load()
# Read just one/some sheets
df = CensusLoader("census.xlsx", country="bangladesh", sheet="Merged_All_Table").load()
# Combine several single-topic sheets side-by-side on a shared key,
# instead of stacking rows (use this when each sheet is a different
# topic — household counts, gender split, literacy — all keyed by the
# same District column)
df = CensusLoader("census.xlsx", country="bangladesh", merge_on="District").load()
CLI
tlf-census-stats --country bangladesh --data census.xlsx --export report.html
Run with no flags at all for a fully interactive walkthrough (file path → sheet selection → stack-vs-merge → export format):
tlf-census-stats
For unattended/scripted runs, --yes disables all prompting and fails loudly (rather than silently guessing) if something required is missing:
tlf-census-stats --yes --country nepal --data nepal_census.csv --export out.csv
Full flag list: tlf-census-stats --help
Combining with tlf-data-cleaning
Most census data doesn't start out clean — it's published as a PDF. tlf-data-cleaning (in the separate TLF-Data-Manager repo) handles extraction and cleaning; there's no runtime dependency between the two packages, they compose through the canonical CSV shape above.
Three ways data reaches this package:
- Already-clean CSV/Excel/JSON — use
CensusLoaderdirectly, no other package needed. - Flat-country PDF (Bangladesh, Pakistan, etc.) —
tlf-data-cleaning'sCleaningPipelinedoes the whole extract-and-clean step. - India's hierarchical PDF —
tlf-data-cleaning'sPDFTableExtractordoes raw extraction only; this package'sIndiaCensusTransformerreshapes the nested INDIA → STATE → DISTRICT → SUB-DISTRICT structure into canonical rows (a generic rename/strip/coerce pipeline can't do this reshaping).
Full worked examples for all three: see tlf-data-cleaning's README.
Tests
pytest tests/ -v
tests/fixtures/ holds small, test-owned sample data (deliberately separate from the demo data bundled with the package itself, in tlf_census_stats/data/sample/, which backs the CLI's built-in --country nepal/bangladesh/india defaults).
The India PDF integration test (test_india_transformer.py) gracefully skips unless tlf-data-cleaning is installed alongside this package and its tests/fixtures/india_census_sample.pdf fixture is present at ../../tlf-data-cleaning/tests/fixtures/ — no cross-repo dependency is required for this package's own test suite to pass.
Metadata
Release files for tlf-census-stats 0.1.5
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 |
|---|---|---|---|---|
| tlf_census_stats-0.1.5.tar.gz | 35.7 kB | Without provenance | Details for tlf_census_stats-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tlf_census_stats-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for tlf_census_stats-0.1.5-py3-none-any.whl |
Total release size: 69.5 kB
Release files / tlf_census_stats-0.1.5.tar.gz
| Download URL | tlf_census_stats-0.1.5.tar.gz |
|---|---|
| Size | 35.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c5845ac09e28f446e98875c997467042608d272a72b06bf41e5eb49b60987ef
|
|
BLAKE2b-256 checksum How to use checksums |
dbd6b7b44e29719dc9dee91d82ae3b7cbeaf5ddf844ea2ad81ffc215c89420cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / tlf_census_stats-0.1.5-py3-none-any.whl
| Download URL | tlf_census_stats-0.1.5-py3-none-any.whl |
|---|---|
| Size | 33.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ee397ded6d89f129584d229624741befe205711ca99e7a051c04cf91a6106d09
|
|
BLAKE2b-256 checksum How to use checksums |
b588dc4bc69c92320749372311b8c52523a46af8aef4306969a4a06a3236a317
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for tlf-census-stats 0.1.5
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.