Independent · v1.0

Spain Book Analytics

A versioned data project on reading in Spain: surveys, population, library loans and book catalogues, with 28.6M public Madrid loan rows in v1.0.

The problem

My coworker Bea wanted to know who reads what in Spain, especially young readers. She looked for a dataset that could answer it and couldn’t find one.

The data exists, but it’s spread across population estimates, reading surveys, library records, bestseller lists and book catalogues. They don’t describe the same people or measure the same thing. So before estimating anything, I made the sources comparable without hiding where they differ.

The sources

FGEE’s 2025 reading survey reports 76.9% leisure reading for ages 14–24. INE publishes population by single year of age, and my target group is 15–24. I can build that population from INE, but I can’t take 14-year-olds out of FGEE’s estimate without survey detail I don’t have. So both bands stay as they are, and every comparison says so.

Illustrative · native age domains
FGEE reading surveyone estimate
14–24
INE populationsingle years
1415161718192021222324
Bestsellers / eBibliono reader age
edition ranksservice loans

Bestseller lists give positions, not sales. Library statistics count loans, not readers. An ISBN identifies an edition, not a work, so the matching code refuses ambiguous joins instead of guessing.

Illustrative · fictional edition records

Edition → work

Each ISBN identifies an edition candidate. Reviewed links can connect editions to one work; ambiguous matches stay unresolved.

HardbackISBN A
PaperbackISBN B
TranslationISBN C
Three edition candidates

Version 1.0 adds the Madrid municipal library loans published on datos.madrid.es, one file per month from October 2014 to August 2026. There are 139 monthly files for 143 calendar months: four months are missing, and the May 2025 file repeats April. Over those years the export used 11 different header layouts, and older files don’t escape quotes inside book titles.

Architecture and decisions

The pipeline follows raw → bronze → silver → gold. Raw keeps source files as downloaded, bronze parses them into typed Parquet, silver cleans and conforms them, and gold holds analytical tables with explicit definitions. Python and Polars do the transformations; DuckDB handles queries and joins. Population counts, survey estimates, loans and rankings each keep their own grain.

The sources have different reuse terms, so the project has two profiles. The public profile uses statistics I can redistribute: INE, eBiblio and a small set of FGEE figures with attribution. The local research profile keeps non-redistributable research catalogues on my machine. Between the two sits a deterministic publication gate that denies by default. It checks file hashes, the reviewed rights policy and every upstream dependency. If an output’s lineage touches a restricted source, it’s blocked, even after the restricted columns are dropped or averaged away.

Illustrative · publication gate

Two source tiers

Public: INE, eBiblio and selected FGEE figures. Restricted: non-redistributable research catalogues kept local.

The deterministic gate blocks any artifact whose lineage touches restricted sources. The public sample builds independently and produces a local approved bundle.

Choose a lineage path.

For Madrid, the reader matches each file to one of the 11 known header signatures and rejects anything unknown or ambiguous instead of guessing column positions. Rows with the wrong number of fields are quarantined. Within a month, a repeated copy barcode and loan date counts as one loan event; that removes duplicated records, not people. Overlaps between neighbouring months are measured and reported, not silently dropped.

A loan isn’t a reader. Each record has a card type and the section the copy belongs to, but no age. Reading ages into card types would be my inference, so I don’t report ages.

In gold, the Madrid loans form a star schema: a fact table of monthly loan counts with dimensions for date, branch and network, card type, format and section. A semantic layer defines each metric once, with its grain, additivity and suppression rule. Cells under five loans are withheld, not shown as zero.

What it does today

Version history · v0.1 → v1.0 → v2.0 → v3.0

How the project has grown

  1. v0.1Research prototype and publication gateShippedSep–Oct 2026

    Heterogeneous sources side by side, each at its own grain, and a gate that decides what can leave the machine.

    • 6,073,841 rows in six local research tables, mixing public statistics with non-redistributable research catalogues kept local. Different grains, not unique books or readers.
    • Raw → bronze → silver → gold on Parquet and DuckDB, with a run manifest for every build.
    • Default-deny publication gate: file hashes, reviewed rights policy and transitive lineage. It approves 14 artifacts in the public sample.
    • Offline public sample: 22 INE observations, 10 eBiblio metrics, 39 FGEE figures. 41 tests passing at the 2026-10-10 verification.
    • Analytical interface kept out of the pipeline repository.

    tag v0.1 · not published yet

  2. v1.028.6M public loan rows, dimensional model and BIShipped · CurrentNov 2026

    Nearly twelve years of Madrid municipal library loans from datos.madrid.es, cleaned, deduplicated and checked against an official figure.

    • 139 monthly files, October 2014 to August 2026, read through 11 explicit header signatures. Unknown layouts are rejected.
    • 28,587,254 raw rows → 615,244 in-month duplicates removed → 27,883,133 analytical rows. May 2025 is excluded: it repeats April.
    • BCDI network, first half of 2026 (S1-2026): 831,345 deduplicated loans against the published municipal figure of 832,916 (0.998, or 99.8%). Scope of the municipal figure still to be confirmed.
    • 254 tests passing, 53 of them for the Madrid reader, on synthetic files.
    • Gold star schema: monthly loan counts by date, branch and network, card type, format and section.
    • Semantic layer: one definition per metric, with grain, additivity and suppression of cells under five loans.
    • Classic BI mini-dashboard over the published aggregates, at /work/spain-book/dashboard/.
    • Public repository from a fresh, reviewed export, tagged v1.0.0, with CI on GitHub Actions.

    tag v1.0.0 ↗

  3. v2.0Databricks Free Edition: PySpark, Delta Lake and Unity CatalogNext · PlannedAfter v1.0

    The same pipeline and the same 28.6M rows on Databricks Free Edition, at no cost.

    • PySpark and Delta Lake tables governed by Unity Catalog.
    • Deployed with Databricks Asset Bundles from GitHub Actions CI, plus a Databricks SQL dashboard.
    • Exact reconciliation of the 28.6M rows between Polars/DuckDB and PySpark/Delta, with the same tests, gate and metric definitions as v1.0.
    • Idempotent monthly load with MERGE, and a before-and-after benchmark of clustering and partitioning.

    Planned, not started. Nothing in v2.0 is built yet.

    tag v2.0 · not published yet

  4. v3.0Predictive BI on the same gold layerPlannedAfter v2.0

    Research on BI that flags what changed before someone asks, built on the v1 and v2 gold tables.

    • Automatic flagging of series breaks. Test case: December 2017, when the BP network enters the Madrid data.
    • Anticipating the views an analysis is likely to need next.
    • Reads the existing gold tables and metric definitions, not a separate copy.

    Research stage. Nothing here is built.

    tag v3.0 · not published yet

The first version runs a public sample offline: 22 INE population observations, 10 eBiblio metrics and 39 selected FGEE figures. The gate checks 14 artifacts before approving the bundle. The full local research run covers 6,073,841 rows across six tables. Those are rows at different grains, not unique books or readers.

Version 1.0 reads 28,587,254 raw loan rows from Madrid. Removing 615,244 in-month duplicates and excluding May 2025 leaves 27,883,133 rows for analysis. As a check, the BCDI network’s first half of 2026 gives 831,345 deduplicated loans against 832,916 in a municipal note: 99.8%. The municipal figure’s exact scope still needs confirming, and older years have no comparable reference, so this checks recent months only.

The test suite has 254 passing tests; the 53 for the Madrid reader use synthetic files, not real loans. The Madrid figures on this page are aggregates; no loan rows are published. Origen de los datos: Comunidad de Madrid y Ayuntamiento de Madrid. Data source: Comunidad de Madrid and Ayuntamiento de Madrid.

The code is on GitHub, exported from a reviewed tree with fresh history, tagged v1.0.0 and tested in CI. The interactive dashboard is a classic BI view of the published aggregates.

Limits and what’s next

The piece Bea asked about, which titles each age group reads, is still missing. Neither the local research sources nor Madrid’s loans record a reader’s age or country. More rows can’t supply a field that was never collected. An FGEE breakdown of age by title, or a survey that asks both, could close that gap.

Version 2.0 is planned, not built: the same 28.6M rows on Databricks Free Edition, at no cost. PySpark and Delta Lake tables under Unity Catalog, deployed with Asset Bundles from GitHub Actions, and a Databricks SQL dashboard. Results must match the Polars and DuckDB run exactly, with an idempotent monthly MERGE load and a clustering and partitioning benchmark.

Version 3.0 is research on predictive BI over the same gold tables and metric definitions. The first test is flagging series breaks automatically: in December 2017 the BP network enters the Madrid data, so loans jump because coverage changed, not because reading did. A tool that misses that would report it as a trend.