Skip to content

Count records per day to find incomplete days

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.

The data dictionary says one row is one reading for one gauge on one day. This tutorial tests that claim. A day counted twice inflates a total, and a missing day shrinks it, and neither shows up as a blank value.

You will: know, for each gauge, whether July has exactly one row per day.

Time: 5 to 10 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

  1. Work out what a complete table would hold: 5 gauges × 31 days in July.

    You should see: 155. The table has 152 rows, so something is uneven.

  2. Count the rows for each gauge:

    readings.groupby("gauge_id").size()
    

    You should see:

    gauge_id
    G01    27
    G02    31
    G03    32
    G04    31
    G05    31
    dtype: int64
    
  3. Count the distinct days for each gauge:

    readings.groupby("gauge_id")["date"].nunique()
    

    You should see: G03 with 31 days, not 32, and G01 still with 27.

    gauge_id
    G01    27
    G02    31
    G03    31
    G04    31
    G05    31
    Name: date, dtype: int64
    
  4. Find any gauge and day with more than one row:

    per_day = readings.groupby(["gauge_id", "date"]).size()
    per_day[per_day != 1]
    

    You should see:

    gauge_id  date
    G03       2026-07-05    2
    dtype: int64
    
  5. List the days on which G01 has no row:

    july = pd.date_range("2026-07-01", "2026-07-31").strftime("%Y-%m-%d")
    sorted(set(july) - set(readings.loc[readings["gauge_id"] == "G01", "date"]))
    

    You should see: four consecutive days.

    ['2026-07-22', '2026-07-23', '2026-07-24', '2026-07-25']
    
  6. In a Markdown cell, note both findings and what each does to a monthly total.

    You should see: your note in the notebook, beside the evidence.

Check it worked

The numbers reconcile: 155 expected rows, plus 1 repeated row, minus 4 missing days, is 152, the size of the table.

If it didn't

Step 4 returns an empty result. You ran it on a table from which repeated rows had already been removed, for example after drop_duplicates(). Run the notebook's first cell again to reload the file, then repeat the step.

Next

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.