AnalystPath

Yearly Billboard Revenue per Panel

PandasHardSenior level~10 min

Problem

An outdoor-advertising company rents billboard panels under contracts that may run across several calendar years. Each contract charges a flat daily rate for every day inside its window (both endpoints inclusive).

`panels` (`panels.csv`): `panel_id`, `panel_name` — one billboard panel per row.

`contracts` (`contracts.csv`): `panel_id`, `window_start`, `window_end`, `daily_rate` — each row is a rental running from `window_start` to `window_end` inclusive, billed at `daily_rate` per day.

For the reporting years **2021, 2022, and 2023**, report the revenue earned on each panel in each year that it earned anything. Yearly revenue = (number of contract days that fall inside that calendar year) * `daily_rate`.

Return the columns `panel_id`, `panel_name`, `report_year` (as text) and `revenue`. Order by `panel_id` then `report_year`.

Input data

Example rows — the live problem includes the full dataset.

panels
panel_idpanel_name
1Harbor Gate
2Maple Cross
3River Bend
contracts
panel_idwindow_startwindow_enddaily_rate
12022-01-252022-02-28100
22021-12-012023-01-0110
32022-12-012023-01-311

Expected output

Your answer should return 6 rows with the columns panel_id, panel_name, report_year, revenue.

Starter code (Pandas (Python))

import pandas as pd

def yearly_panel_revenue(panels: pd.DataFrame, contracts: pd.DataFrame) -> pd.DataFrame:
    # Your code here
    return panels

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