AnalystPath

Water Meters Over the Monthly Cap

PandasMediumMid level~10 min

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.

meters
meter_idmonthly_cap
10050
20040
30030
readings
reading_idmeter_idflow_typevolumeread_day
1100Usage602023-01-10 00:00:00
2100Usage702023-02-12 00:00:00
3100Credit1002023-02-15 00:00:00
4200Usage502023-01-05 00:00:00
5200Usage602023-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 meters

Solve 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

Related Pandas questions