AnalystPath

Lookup Reservoir Levels

PandasEasyJunior level~10 min

Problem

A water authority stores the recorded level of each reservoir at the end of selected years. Analysts submit lookup requests for a reservoir in a given year; if no level was recorded for that reservoir-year, the answer is `0`.

DataFrame `readings` (from `readings.csv`) has columns `reservoir_id`, `year`, `level_cm` — the recorded end-of-year level in cm for a reservoir.

DataFrame `lookups` (from `lookups.csv`) has columns `reservoir_id`, `year` — one request per row.

For every lookup, return `reservoir_id`, `year`, and `level_cm`. If the reservoir-year is missing from `readings`, report its level as `0`. Rows may be returned in any order.

Input data

Example rows — the live problem includes the full dataset.

readings
reservoir_idyearlevel_cm
12018100
7202030
13201940
12019113
22008121
lookups
reservoir_idyear
12019
22008
32009
72018
72019

Expected output

Your answer should return 7 rows with the columns reservoir_id, year, level_cm.

Starter code (Pandas (Python))

import pandas as pd

def resolve_lookups(readings, lookups) -> pd.DataFrame:
    # Your code here
    return readings

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