Bucket Daily Rainfall
Problem
A weather station records the total rainfall for each day. You are given a DataFrame `rain_log` loaded from `rain_log.csv`:
```text
+------------+------+
| Column | Type |
+------------+------+
| reading_id | int |
| rain_mm | int |
+------------+------+
reading_id is the primary key. Each row holds one day's total rainfall in millimetres.
```
Classify each day into one of three bands:
- `'Dry'`: rainfall strictly less than 10 mm.
- `'Moderate'`: rainfall in the inclusive range [10, 50] mm.
- `'Heavy'`: rainfall strictly greater than 50 mm.
Return a DataFrame with one row per band, columns `band` and `day_count` (the number of days in it). The result must contain all three bands; a band with no days reports 0. Order does not matter.
Input data
Example rows — the live problem includes the full dataset.
| reading_id | rain_mm |
|---|---|
| 3 | 109 |
| 2 | 7 |
| 8 | 88 |
| 6 | 92 |
Expected output
Your answer should return 3 rows with the columns band, day_count.
Starter code (Pandas (Python))
import pandas as pd
def bucket_daily_rainfall(rain_log) -> pd.DataFrame:
# Your code here
return rain_logSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock