Water Meters Over the Monthly Cap
Problem
You are given two DataFrames. `meters` has columns `meter_id`, `monthly_cap` (the allowed monthly water volume in litres). `readings` has columns `reading_id`, `meter_id`, `flow_type`, `volume`, `read_day` (a datetime string). `flow_type` is either `'Usage'` or `'Credit'`; only `'Usage'` counts toward consumption — `'Credit'` rows are refunds and must be ignored.
A meter is **over-cap** if its total monthly `'Usage'` volume exceeds its `monthly_cap` in **two or more consecutive calendar months**.
Report the `meter_id` of all over-cap meters, in any order.
Input data
Example rows — the live problem includes the full dataset.
| meter_id | monthly_cap |
|---|---|
| 100 | 50 |
| 200 | 40 |
| 300 | 30 |
| reading_id | meter_id | flow_type | volume | read_day |
|---|---|---|---|---|
| 1 | 100 | Usage | 60 | 2023-01-10 00:00:00 |
| 2 | 100 | Usage | 70 | 2023-02-12 00:00:00 |
| 3 | 100 | Credit | 100 | 2023-02-15 00:00:00 |
| 4 | 200 | Usage | 50 | 2023-01-05 00:00:00 |
| 5 | 200 | Usage | 60 | 2023-03-05 00:00:00 |
Expected output
Your answer should return 1 row with the columns meter_id.
Starter code (Pandas (Python))
import pandas as pd
def water_meters_over_cap(meters, readings) -> pd.DataFrame:
# Your code here
return metersSolve 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