The Problem
Real data moment
Every CSV so far has had a header row explaining itself. Real government data often doesn't. Here's one real line from NOAA's GHCN-Daily archive — genuine daily weather records for Central Park, New York, station USW00094728, one of the longest continuously-operating stations in the US:
USW00094728202301TMAX 128 W 133 W 144 W 189 W 100 W 94 W 72 W ...
No commas, no header, no obvious column boundaries — just packed positional text. NOAA's own format documentation is the only thing that makes this readable at all: ID in columns 1-11, YEAR in 12-15, MONTH in 16-17, ELEMENT in 18-21, then a VALUE/MFLAG/QFLAG/SFLAG group repeating once for every day of the month, starting at column 22.
The gotcha
NOAA's own documentation states it plainly: missing = -9999. Here's a real July 2026 record for the same station — genuinely incomplete, since NOAA hadn't recorded temperatures for the rest of the month yet at the time this file was fetched:
row = df[(df["year"] == 2026) & (df["month"] == 7) & (df["element"] == "TMAX")]
value_cols = [f"value{d}" for d in range(1, 32)]
naive_avg = row.iloc[0][value_cols].astype(float).mean() / 10
print(round(naive_avg, 2))
-302.7
Negative 302.7 degrees Celsius — colder than deep space, for a New York City July. -9999 isn't a real temperature; it's a placeholder, and to .mean(), a placeholder that looks like a number is just a number. Ten of this month's 31 day-slots hadn't happened yet when this file was fetched, and every one of them silently dragged the "average" toward absolute zero and past it.
df_clean = pd.read_fwf("USW00094728.dly", colspecs=colspecs, names=names, header=None, na_values=[-9999])
row = df_clean[(df_clean["year"] == 2026) & (df_clean["month"] == 7) & (df_clean["element"] == "TMAX")]
correct_avg = row.iloc[0][value_cols].astype(float).mean() / 10
print(round(correct_avg, 2))
29.3
One argument, na_values=[-9999], and the same real data produces 29.3°C (about 85°F) — an entirely believable New York July high. The fix isn't a smarter averaging formula; it's telling pandas, up front, which values aren't really data.
-302.7°C should have been the tell, not a number to trust
No error was raised anywhere in the naive version — .mean() ran successfully and printed a number. The only signal that something was wrong was the number itself being physically impossible. That's the actual discipline this lesson is teaching: treat an extreme, implausible statistic as a reason to go looking for an unflagged sentinel, rather than as an interesting finding to report.
A different station's real February record has temperature values for days 1-28, then -9999 for days 29, 30, and 31. Averaging all 31 raw values (without na_values) for this February gives a suspiciously low result. What's the most likely explanation?
NOAA's own documentation confirms this directly: every month's record reserves 31 day-slots regardless of how many days that month actually has, and "if the month has less than 31 days, then the remaining variables are set to missing." February's days 29-31 aren't a data gap in the usual sense — they're structurally guaranteed to be -9999 for any February, a predictable padding pattern rather than a surprising one, but one a naive average will still silently wreck itself on if na_values isn't set.