Tally a quality flag before you trust a number¶
Draft: not yet validated
The code on this page was run inside MESA JupyterLab on 2026-11-13 and produced the output shown. Nobody has yet followed the steps there by hand, so a menu or a screen may differ. Tell us what you find.
Many datasets carry a column in which the instrument or the provider marks readings it doubts. A total computed without looking at that column includes those readings.
You will: know how many readings are flagged, which ones, and at which gauges.
Time: 5 minutes. You need: the notebook from
Load a file from your Data Store into a notebook, open in
MESA JupyterLab, with its first cell run so that readings
and gauges exist.
Steps¶
-
Read what the flag means in the data dictionary.
You should see: blank, or
Sfor a reading the sensor marked suspect. -
Count the rows for each flag value, blanks included:
readings["flag"].value_counts(dropna=False)You should see:
flag NaN 150 S 2 Name: count, dtype: int64 -
Check that nothing is left over: 150 + 2 = 152, the number of rows in the table.
You should see: the counts add up, and no flag value that the dictionary does not list.
-
Look at the flagged rows:
readings[readings["flag"] == "S"]You should see:
gauge_id date value flag 76 G03 2026-07-18 0.0 S 129 G05 2026-07-09 180.0 S -
Count flags by gauge:
pd.crosstab(readings["gauge_id"], readings["flag"].fillna("blank"))You should see:
flag S blank gauge_id G01 0 27 G02 0 31 G03 1 31 G04 0 31 G05 1 30 -
In a Markdown cell, write down what you will do with flagged readings and why: keep them, leave them out, or report the result both ways.
You should see: your decision recorded in the notebook, where a reader of your result can find it.
Check it worked¶
You can say how many readings are flagged (2), where they are, and what your analysis does with them. The tally does not make that decision for you. A flag marks a doubt, not an error: one of these readings is far outside its gauge's range, the other is an ordinary dry day.
If it didn't¶
The tally shows only S 2. dropna=False is missing, so the blanks were left
out and you cannot check the counts against the row total. Add it and run the cell
again.
Next¶
- Count records per day to find incomplete days
- Reference: pandas.Series.value_counts and pandas.crosstab.
Not yet validated by a person in MESA JupyterLab. Drafted with AI assistance on 2026-11-12; the code was run there on 2026-11-13 (pandas 3.1.1, DuckDB 2.0.0).
Machine-readable versions of this page: Markdown twin · raw source on GitHub · llms.txt · llms-full.txt (whole site). See For AI agents.