AnalystPath

Branches With Above-Average Water Flow

PandasMediumMid level~10 min

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
branch_idcityarea_code
1RiversideRV
2HilltopHT
3LakeviewLV
4SeasideSS
meter
meter_idbranch_id
101
111
202
212
303
flow_log
source_metertarget_meterlitres
103033
20304
102059
1140102
1140330

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 branch

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