Water quality: clean the pH readings
Scenario
You are a data analyst. A catchment monitoring programme logs pH from field probes. Some readings are impossible (below 0 or above 14) because probes drift when batteries fail.
Question
Drop invalid pH readings, fill missing turbidity with the median, and report the mean pH per site.
Your task
- Keep only rows where ph is between 0 and 14
- Fill missing turbidity with the column median
- Group by site and take the mean pH
Intermediate · Record Counting & Average Calculations — question 11 of 30
1. Choose your dataset
Pick an industry and a size. Your code and results change to match.
Water quality: clean the pH readings
Drop invalid pH readings, fill missing turbidity with the median, and report the mean pH per site.
Your code cell is below. Press Check my answer to run the cell — the result appears as Out [1].
💡 Explain my whole code, line by line (hover any word in the editor for a tip)
🌈 In short — no coding words
Altogether: this script runs top to bottom, one line at a time, building up the answer step by step.
Dataset & schema
water_samples
The tiny starter data. Bigger data scrolls.
Fields
| site | ph | turbidity_ntu | sample_date |
|---|---|---|---|
| Vaal-01 | 7.2 | 3.1 | 2026-02-01 |
| Vaal-01 | 22 | 2.9 | 2026-02-08 |
| Klip-02 | 6.4 | NaN | 2026-02-01 |
| Klip-02 | 6.8 | 5.2 | 2026-02-08 |
$ Press “Check my answer” — results appear here.Your next steps
Each item turns green when your answer includes it.
- Filters pH range
- Upper pH bound
- Fills missing turbidity
- Uses the median
- Groups by site
- Takes the mean