<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MonetizationKit Data Notes]]></title><description><![CDATA[MonetizationKit Data Notes]]></description><link>https://monetizationkit.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 20 Nov 2026 19:25:02 GMT</lastBuildDate><atom:link href="https://monetizationkit.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Making a data write-up fail its build when the numbers drift]]></title><description><![CDATA[Assertions next to the prose, pinned snapshots, and the country code that pandas turns into a missing value.]]></description><link>https://monetizationkit.hashnode.dev/making-a-data-write-up-fail-its-build-when-the-numbers-drift</link><guid isPermaLink="true">https://monetizationkit.hashnode.dev/making-a-data-write-up-fail-its-build-when-the-numbers-drift</guid><category><![CDATA[jupyter]]></category><category><![CDATA[Python]]></category><category><![CDATA[pandas]]></category><category><![CDATA[Data Science]]></category><dc:creator><![CDATA[Amy Lee]]></dc:creator><pubDate>Sat, 07 Nov 2026 14:35:43 GMT</pubDate><content:encoded><![CDATA[<p>Data write-ups go stale in a quiet way. The CSV gets refreshed, the charts regenerate, and the paragraph that says "50 countries, 3,080 channels" keeps saying it. Nobody notices until a reader does.</p>
<p>We publish a small dataset of YouTube monetization signals by country, along with a book that explains it. Here is how the book keeps its text and its data from drifting apart.</p>
<h2>Compute the numbers, then assert the ones the text quotes</h2>
<p>The book is built from notebooks, so every table and figure is computed from the CSV when the book is built. That covers the charts. It doesn't cover sentences on other pages that quote a number by hand.</p>
<p>So the first notebook chapter checks those numbers before any analysis runs:</p>
<pre><code class="language-python">checked = snapshot["channels_checked"]
assert (snapshot[VERDICTS].sum(axis=1) == checked).all()
assert checked.min() &gt;= 30

countries = len(snapshot)
channels = int(checked.sum())

# Figures quoted on the text pages of this book
assert (countries, channels) == (50, 3080)
# "one channel in five" could not be determined
assert round(snapshot["unable_to_determine"].sum() / channels, 2) == 0.20
</code></pre>
<p>The first two lines check that the file is consistent with itself: each country's verdicts add up to the number of channels checked, and no published country is below the 30-channel cutoff. The last two check the file against the prose. The build executes the notebooks, so if a refresh changes these totals, the assertion fails during the build instead of in front of a reader. Then you go find the sentences that quote them.</p>
<p>It's a crude test, and that's the point. One assert per number that appears in a paragraph is cheap to write and easy to read.</p>
<h2>Pin the snapshot the text describes</h2>
<p>The repository's main CSV is replaced with each new snapshot and now holds October. The book describes September, so it reads the September copy, which is kept unchanged:</p>
<pre><code class="language-python"># The September 2026 snapshot. The CSV in the repository root now holds October 2026,
# so the book reads the unchanged September copy kept with the analysis.
SEPTEMBER_CSV = (
    REPO / "analysis" / "2026-10-membership-rule" / "data"
    / "youtube-monetization-signals-by-country-2026-09.csv"
)
</code></pre>
<p>Without this, the September chapter would silently start describing October data the first time someone rebuilt it.</p>
<h2>Namibia is not a missing value</h2>
<p>Country codes look harmless until pandas reads one:</p>
<pre><code class="language-python"># keep_default_na=False: "NA" is Namibia's code, not a missing value
snapshot = pd.read_csv(SEPTEMBER_CSV, keep_default_na=False)
</code></pre>
<p>By default, <code>read_csv</code> treats the string <code>NA</code> as missing. In a file keyed by ISO country codes, that quietly drops Namibia's code. The consistency asserts above would catch some versions of this, but not all, so the fix goes in the read call itself.</p>
<h2>What this doesn't solve</h2>
<p>The asserts only cover numbers someone remembered to assert. A new sentence with a new figure needs a new line in the check cell. The practical habit is to add the assert in the same change as the sentence.</p>
<p>The book, with both notebook chapters and their code, is here: <a href="https://monetizationkit.com/data/book/">YouTube monetization signals by country</a>.</p>
<p>Disclosure: I work on MonetizationKit, which publishes the dataset.</p>
]]></content:encoded></item></channel></rss>