Nigerian election analytics and data quality system
A Python system that validates, cleans and analyses Nigerian election data, and tests its own checks against deliberately planted defects.
- Status
- In progress
- My role
- Solo project
- Tools
- Python, pandas, Jupyter, pytest, Excel
- Skills
- Data quality rule design, Relational data design, Cleaning with an audit trail, Precision and recall evaluation, Election metrics, Sensitivity analysis, Automated testing
- Data
- Synthetic results with fictional parties; real reference data only
The problem
Election data arrives in pieces: result rows, voter registers, ballot summaries and reference lists, and the pieces rarely agree. If an analyst calculates turnout or vote share straight away, duplicated rows, orphan codes and impossible values flow silently into the conclusions.
This project treats trustworthy data as a precondition for trustworthy analysis. Every number it reports can be traced back to a source record, a documented rule and a logged correction.
The data, and an honest note about it
The vote, voter and ballot figures are synthetic, generated by the project from a fixed seed, and the parties and candidates are fictional. The results demonstrate methods; they are not actual Nigerian election results.
Real reference data is used where it can be trusted: states and geopolitical zones, LGA counts per state, which states hold governorship elections on the general cycle, and INEC’s 2021 polling-unit distribution, transcribed and checked against its totals.
I documented the official data I could not use, and why. INEC’s IReV portal stores polling-unit results as photographed result sheets behind a login, and only began in 2020. I also chose not to generate ward or polling-unit tables, because inventing geographic detail is worse than leaving it out.
How it works
- Relational design. Every table has an explicitly declared grain, so “duplicate” always means something precise.
- Validation framework. 20 reusable rules across completeness, uniqueness, validity, referential integrity, consistency and plausibility, all reporting issues in one uniform format.
- Cleaning with an audit trail. A value is corrected only when the right value is knowable, mechanically or from an authoritative reference table. Otherwise the record is kept and marked as not eligible for analysis. Records are quarantined, never guessed, and missing values never become zero.
- Election metrics. Turnout, vote share, margins, closest races, strongholds, swing, rejected ballots, and historical and regional patterns, across the 2015, 2019 and 2023 cycles.
- Sensitivity analysis. The key metrics are recalculated with and without questionable records, to test whether the conclusions depend on them.
Testing the tests
To check that the rules actually catch problems, the project plants 171 known defects in the raw data and keeps a defect-free copy as an answer key. That makes it possible to measure each rule’s precision and recall rather than assume it works.
Rules I held to
- Presidential and governorship votes are never added together.
- Turnout is calculated as a ratio of sums, not an average of percentages.
- Margins are reported in percentage points.
- Plausibility flags are reasons to investigate, not evidence of error or misconduct.
What I would do next
- Load INEC’s declared state-level results for 2023, then 2019 and 2015.
- Pilot a documented transcription of IReV result sheets for one LGA and reconcile it with the collated totals.
- Add a step that compares sources when two report the same unit differently.
- Add maps once verified boundaries and official codes are available.