DEV Community

bao han
bao han

Posted on

Keep unknown registry outcomes separate from observed negatives in Python

A blank outcome in a registry export can mean follow-up is still pending. If you convert every blank to a negative before counting events, you silently change the denominator. Preserve three states through the first summary.

This example uses fictional rows and keeps unexpected values visible as errors.

rows = ["yes", "no", "", "yes", "pending", "no"]
outcomes = {"yes": True, "no": False, "": None, "pending": None}
parsed = [outcomes[value.strip().lower()] for value in rows]

events = sum(value is True for value in parsed)
negatives = sum(value is False for value in parsed)
unknown = sum(value is None for value in parsed)
observed = events + negatives

assert (events, negatives, unknown) == (2, 2, 2)
print(f"{events}/{observed} observed events; {unknown} outcomes unknown")
Enter fullscreen mode Exit fullscreen mode

The output is 2/4 observed events; 2 outcomes unknown. Before using the observed proportion, check the registry's codebook and whether pending outcomes are concentrated in one period or group. Preserve the raw status alongside the parsed status in the export so the mapping can be audited.

Python language reference on identity comparisons

Top comments (0)