Branches With Above-Average Water Flow
Problem
A municipal water utility records every metered flow between water meters. Each meter belongs to one branch office.
`branch` columns: `branch_id`, `city`, `area_code`.
`meter` columns: `meter_id`, `branch_id`.
`flow_log` columns: `source_meter`, `target_meter`, `litres` - one logged transfer per row.
Return the branches whose **average flow per logged transfer is strictly greater than the global average flow per transfer** across the whole network. A meter participates in a transfer whether it is the source or the target of the flow.
Return one column named `region` (the branch city). Order does not matter.
Input data
Example rows — the live problem includes the full dataset.
| branch_id | city | area_code |
|---|---|---|
| 1 | Riverside | RV |
| 2 | Hilltop | HT |
| 3 | Lakeview | LV |
| 4 | Seaside | SS |
| meter_id | branch_id |
|---|---|
| 10 | 1 |
| 11 | 1 |
| 20 | 2 |
| 21 | 2 |
| 30 | 3 |
| source_meter | target_meter | litres |
|---|---|---|
| 10 | 30 | 33 |
| 20 | 30 | 4 |
| 10 | 20 | 59 |
| 11 | 40 | 102 |
| 11 | 40 | 330 |
Expected output
Your answer should return 2 rows with the columns region.
Starter code (Pandas (Python))
import pandas as pd
def branches_with_above_average_water_flow(branch, meter, flow_log) -> pd.DataFrame:
# Your code here
return branchSolve 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