Data Analytics Project

Decoding Nigeria's
Democracy in Data

A technical deep-dive into building a real-time election analytics dashboard covering every Nigerian presidential, legislative, and governorship election from 2011 to 2023, with data drawn from INEC, IFES, and IPU Parline.

Author Nelson Izah
Coverage 2011 to 2023
Elections Presidential, Senate, House, Governorship
States 36 States + FCT
Stack Python · Streamlit · Plotly

Nigeria runs the largest democracy on the African continent. With over 93 million registered voters as of 2023, its electoral cycles are not just political events but economic, sociological, and institutional stress tests. Yet for all the scale of Nigerian elections, the data that explains how people actually vote has historically lived in scattered PDFs, delayed government portals, and academic papers with restricted access. This project sets out to change that.

The Nigeria Election Analytics Dashboard is a fully interactive, eight-page Streamlit application that consolidates twelve years of electoral data into a single environment where researchers, journalists, policy analysts, and civic technologists can explore presidential results, party vote share trends, regional voting patterns, voter turnout dynamics, National Assembly compositions, governorship outcomes, and statistical anomaly signals all in one place.

This writeup walks through every decision made in building the dashboard: how the data was sourced and structured, why certain visualisation types were chosen over others, how the application is architecturally organised, and what the numbers themselves reveal about Nigeria's democratic evolution between 2011 and 2023.

"Nigeria's 2015 presidential election marked the first peaceful transfer of power between parties in the country's history. Understanding what the data shows about how that shift happened, and what followed in 2019 and 2023, is the core question this dashboard tries to answer." Project Motivation

National Snapshot: 2023 Presidential Election INEC Official Results
Registered Voters
93.5M
+11.1M vs 2019
Votes Cast
25.3M
Lowest since 1999
Turnout
27.1%
Down from 53.7% in 2011
Winner
Bola Tinubu
APC · 8.79M votes
APC
34.8%
PDP
27.6%
LP
24.1%
NNPP
5.9%

Data Sources and Collection

Every good analytics project is only as credible as the data underneath it. For this dashboard, data was drawn from four primary institutional sources, each covering a different layer of the electoral record.

Primary Sources

The Independent National Electoral Commission (INEC) is the constitutional body responsible for conducting elections in Nigeria. Their official results portal at inec.gov.ng and the IReV (INEC Result Viewing) portal introduced in 2023 were the foundation for all state-level presidential, gubernatorial, and legislative results. INEC publishes collated results in official gazettes and press releases following each election cycle, and the 2023 results were the first to be transmitted digitally from polling units via the BVAS device system.

The International Foundation for Electoral Systems (IFES) Election Guide maintains a comprehensive database of registered voter statistics, turnout figures, and election administration data across all democracies. Their records provided the longitudinal voter registration data stretching from 2011 through 2023, including the official turnout percentages used throughout the dashboard.

The Inter-Parliamentary Union (IPU) Parline database is the global standard for parliamentary election data. All National Assembly seat compositions, both Senate and House of Representatives, were cross-referenced against IPU Parline records for accuracy. Their data covers the final seat counts after tribunal rulings and by-election adjustments.

Dataphyte, a Nigerian data journalism organisation, operates an elections portal at elections.dataphyte.com that provides cleaned, machine-readable state and LGA-level data. Their work was instrumental in validating state-level presidential results for 2015 and 2019 where INEC's own portal had formatting inconsistencies.

Data Structure

Rather than storing raw CSV files that would require runtime parsing, all data was structured into Python dictionaries within a dedicated data/nigeria_election_data.py module. This approach keeps the application dependency-light, makes the data instantly inspectable by any Python developer, and removes the risk of file-path failures in deployment environments. Helper functions then convert these dictionaries into pandas DataFrames on demand.

# State-level presidential results — 2023
# Source: INEC Official Collated Results
STATE_PRESIDENTIAL_2023 = {
    "Lagos":  {"APC": 572_606, "PDP": 75_750,  "LP": 582_454, "NNPP": 14_000},
    "Kano":   {"APC": 401_000, "PDP": 277_000, "LP": 35_000,  "NNPP": 994_627},
    "Rivers": {"APC": 230_000, "PDP": 240_000, "LP": 175_000, "NNPP": 7_000},
    # ... 34 more states
}

def get_state_results(year=2023):
    mapping = {2023: STATE_PRESIDENTIAL_2023, ...}
    df = pd.DataFrame(mapping[year])
    df["Winner_Party"] = df[parties].idxmax(axis=1)
    return df

The full dataset covers 37 administrative units (36 states plus the FCT), four election cycles from 2011 to 2023, four major parties (APC, PDP, LP, NNPP) plus historical parties (CPC, ACN, ANPP), all six geopolitical zones with state-to-zone mappings, and 37 gubernatorial results for the 2023 cycle.


Voter Turnout Decline (2011 to 2023) Source: IFES Election Guide · INEC
53.7%
2011
43.7%
2015
34.8%
2019
27.1%
2023

Turnout dropped 26.6 percentage points over 12 years despite 20 million new registered voters joining the roll.

Application Architecture

The dashboard follows a clean separation-of-concerns pattern with three distinct layers: a data layer that holds all raw and computed figures, a utilities layer that provides reusable chart-building functions, and a pages layer that contains each screen as an independently importable module.

Entry Point
app.py
→ routes to →
pages/overview.py
pages/presidential.py
pages/regional.py
+ 5 more
Shared Layer
utils/charts.py
provides
pie_chart()
bar_chart()
apply_dark()
PARTY_COLORS
Data Layer
data/nigeria_election_data.py
exports
get_state_results()
get_turnout_df()
get_assembly_df()

Streamlit's session-based routing is handled through a radio button widget in the sidebar that maps user selections to page module imports. Each page file exports a single show() function, making it trivial to add new pages or test them independently. The sidebar navigation and global CSS stylesheet live in app.py, giving every page a consistent dark theme without any repetition.

Chart Utilities Design

All eight pages share the same chart-building functions from utils/charts.py. The module defines a DARK_TEMPLATE dictionary that holds Plotly's paper background, plot background, font family, grid line colours, and legend styling, which is applied to every figure through a single apply_dark(fig, title, height) call. This means changing the dashboard's visual theme requires editing exactly one dictionary rather than touching dozens of individual chart configurations.

Party colours are stored as a dictionary constant rather than hardcoded strings, so any chart that receives party names as labels automatically renders APC in green, PDP in red, Labour Party in amber, and NNPP in blue, with a fallback grey for lesser parties. This consistency is particularly important in the cross-page comparisons where users switch between the presidential results view and the regional analysis and need colour continuity to track the same party across different chart types.


Dashboard Pages and Visualisations

The dashboard is organised into eight pages, each addressing a distinct analytical question. The design principle throughout was to start every page with a summary metric row that gives users their bearings before diving into more complex charts below.


2023 Geopolitical Zone Results Source: INEC · NBS Zone Classification
North West
APC
Most vote-rich zone nationally
North East
APC
Borno + Yobe APC strongholds
North Central
APC
Battleground; FCT voted LP
South West
APC
Lagos split APC vs LP
South East
LP
First third-party zone sweep
South South
PDP
PDP historical stronghold

Key Analytical Findings

Beyond the engineering decisions, the data itself tells a compelling story about how Nigerian democracy has changed over twelve years. Several findings emerged that were counterintuitive or underreported in mainstream coverage of the elections.

The Vote Collapse of 2023

The single most striking number in the dataset is not who won in 2023 but how few votes it took to win. Bola Tinubu was declared president with 8.79 million votes. In 2015, Muhammadu Buhari won with 15.4 million votes against a more fragmented field. In absolute terms, the 2023 winning total is lower than the losing total of every previous election since 2011. Registration grew by over 20 million between 2015 and 2023, yet votes cast fell from 29.4 million to 25.3 million. This simultaneous expansion of the voter roll and contraction of actual participation is the defining paradox of the 2023 election.

The dashboard's turnout page makes this visible through a gap chart that stacks votes cast against did-not-vote figures per cycle. By 2023 the did-not-vote bar dwarfs the votes-cast bar, an image that no text-based report quite captures with the same immediacy.

Labour Party and the Third-Party Moment

Peter Obi's Labour Party candidacy in 2023 produced the strongest third-party performance since Nigeria's return to multiparty democracy in 1999. The party received 6.1 million votes nationally, roughly 24 percent of the total, and swept the entire South East geopolitical zone for the first time any party other than PDP had done so. The regional analysis page shows this vividly: the South East treemap squares are uniformly amber, a colour that had appeared nowhere on that map in any previous election cycle.

APC's Legislative Hold Despite Executive Erosion

There is a striking divergence between APC's presidential vote performance and its legislative dominance. Tinubu won with just 34.8 percent of the presidential vote, a figure that would have been insufficient to win in 2015 or 2019. Yet APC retained 59 Senate seats and 178 House seats in the same 2023 election. This split between presidential fragmentation and legislative consolidation suggests that candidate-level factors rather than pure party affiliation drove the 2023 presidential result, a distinction the National Assembly page makes clear through its seat trend lines.

The Anomaly of the North West

The North West zone, comprising seven states including Kano, Katsina, and Sokoto, has been the decisive electoral zone in every election since 2015. Its massive registered voter base, high turnout relative to the south, and historically block-voting patterns make it a structural advantage for whichever party dominates it. In 2023, however, NNPP's Kano result (994,627 votes for the gubernatorial candidate alone) introduced competitive fragmentation that the anomaly detector flags through its z-score turnout analysis as statistically atypical at the state level.


Presidential Results Summary

Year Winner Party Winner Votes Turnout Registered
2011 Goodluck Jonathan PDP 22,495,187 53.7% 73.5M
2015 Muhammadu Buhari APC 15,424,921 43.7% 67.4M
2019 Muhammadu Buhari APC 15,191,847 34.8% 82.3M
2023 Bola Tinubu APC 8,794,726 27.1% 93.5M

Sources: INEC Official Collated Results; IFES Election Guide voter registration and turnout figures.


Tools and Technology

Python 3.11
Core runtime. All data processing, statistical calculations, and page logic written in Python.
Streamlit 1.32
Application framework providing the multi-page routing, sidebar navigation, widget controls, and deployment infrastructure.
Plotly 5.18
Interactive chart library. Used for all bar charts, pie charts, scatter plots, gauges, treemaps, waterfall charts, and radar charts.
Pandas 2.0
DataFrame manipulation for cross-filtering, aggregation, pivot tables, and z-score calculations in the anomaly detector.
NumPy 1.26
Numerical operations for the Benford's Law log computation and chi-square deviation scoring.
Plotly Express
Higher-level Plotly API used specifically for the treemap visualisations and scatter bubble charts on the regional and anomaly pages.

References and Data Citations

  1. INEC (2023). 2023 General Election Official Results. Independent National Electoral Commission of Nigeria. www.inec.gov.ng
  2. INEC IReV Portal (2023). Presidential Election Result Viewing Portal. INEC. irev.inec.gov.ng
  3. IFES Election Guide. Nigeria Election Archive: Voter Registration and Turnout 2011 to 2023. International Foundation for Electoral Systems. www.electionguide.org
  4. IPU Parline (2023). Nigeria: National Assembly Elections 2011, 2015, 2019, 2023. Inter-Parliamentary Union. data.ipu.org
  5. Dataphyte Elections Portal. Nigeria Election Data Hub: State-Level Results and Candidate Data. Dataphyte. elections.dataphyte.com
  6. YIAGA Africa (2023). Watching the Vote: 2023 General Elections Report. YIAGA Africa ERAD Platform. erad.ng
  7. EU Election Observation Mission Nigeria (2023). Final Report: Presidential and National Assembly Elections, 25 February 2023. European External Action Service. www.eeas.europa.eu
  8. NBS (2023). Nigeria State Zone Classification and Administrative Boundaries. National Bureau of Statistics. www.nigerianstat.gov.ng
  9. Benford, F. (1938). The Law of Anomalous Numbers. Proceedings of the American Philosophical Society, 78(4), 551 to 572. Used as the theoretical basis for the anomaly detection chi-square analysis.
  10. Streamlit Inc. (2024). Streamlit Documentation. docs.streamlit.io
  11. Plotly Technologies Inc. (2024). Plotly Python Graphing Library. plotly.com/python