Skip to content

Bring two units onto one scale before comparing

Draft: not yet validated

The code on this page was run inside MESA JupyterLab on 2026-11-16 (pandas 3.1.1, DuckDB 2.0.0) by the site's output check, in a terminal there, and gave the values shown. No person has yet followed the steps, so a menu or a screen may differ. Tell us what you find.

The practice gauges do not all report in the same unit, and the unit is written in a different file from the readings. Until the values share a unit, no comparison between gauges means anything.

You will: have a value_mm column that holds every reading in millimetres, and proof that no row was left unconverted.

Time: 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. List the units in use:

    gauges["unit"].value_counts()
    

    You should see: two units.

    unit
    mm    4
    cm    1
    Name: count, dtype: int64
    
  2. Write down, as a small table of your own, how each unit becomes millimetres:

    to_mm = {"mm": 1, "cm": 10}
    

    You should see: no output. A unit you have not listed here will show up in step 4.

  3. Give each reading its gauge's unit, then convert:

    joined = readings.merge(gauges[["gauge_id", "unit"]], on="gauge_id", how="left", validate="many_to_one")
    joined["value_mm"] = joined["value"] * joined["unit"].map(to_mm)
    joined[joined["gauge_id"] == "G02"].head(3)
    

    You should see: the original value kept, and value_mm ten times larger for this gauge.

       gauge_id        date  value flag unit  value_mm
    27      G02  2026-07-01   0.00  NaN   cm       0.0
    28      G02  2026-07-02   0.00  NaN   cm       0.0
    29      G02  2026-07-03   2.89  NaN   cm      28.9
    
  4. Count the readings that were not converted:

    int(joined["value_mm"].isna().sum())
    

    You should see: 0. A reading with no gauge, or with a unit missing from to_mm, would have an empty value_mm and be counted here.

  5. Compare the largest reading at each gauge, before and after:

    joined.groupby("gauge_id")[["value", "value_mm"]].max()
    

    You should see: G02 no longer far below its neighbours.

               value  value_mm
    gauge_id
    G01        24.90      24.9
    G02         2.92      29.2
    G03        32.50      32.5
    G04        26.40      26.4
    G05       180.00     180.0
    

Check it worked

joined has the same number of rows as readings, step 4 gave 0, and for the four gauges that already reported in millimetres value_mm equals value.

If it didn't

Step 4 gives a number above 0. Some gauge reports in a unit that to_mm does not list. Run joined.loc[joined["value_mm"].isna(), "unit"].unique() to see which, add it to to_mm in step 2, and run steps 3 and 4 again.

Next

Not yet validated by a person in MESA JupyterLab. Drafted with AI assistance on 2026-11-15; the code was run there on 2026-11-16 (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.