AnalystPath

Annual Energy Output Growth by Panel Model

PandasHardSenior level~10 min

Problem

You are given a DataFrame `meter_readings` loaded from `meter_readings.csv` with columns `reading_id` (int), `panel_model` (int), `kwh` (float) and `recorded_at` (datetime string). For each `panel_model`, first sum `kwh` per calendar year (`output_year`) to get `current_output`. Then attach `prior_output` = that same model's total for the immediately preceding year (the year exactly one less); it is null when no reading exists for the prior year. Compute `growth_pct` = round((current_output - prior_output) * 100 / prior_output, 2), null when `prior_output` is null. Return columns `output_year`, `panel_model`, `current_output`, `prior_output`, `growth_pct`, sorted by `panel_model` then `output_year`.

Input data

Example rows — the live problem includes the full dataset.

meter_readings
reading_idpanel_modelkwhrecorded_at
1100200.002021-03-14 09:00:00
2100150.002021-08-02 11:30:00
3100400.002022-05-21 10:15:00
4100100.002022-09-09 14:00:00
5200300.002022-01-10 08:00:00

Expected output

Your answer should return 4 rows with the columns output_year, panel_model, current_output, prior_output, growth_pct.

Starter code (Pandas (Python))

import pandas as pd

def annual_growth(meter_readings) -> pd.DataFrame:
    # Your code here
    return meter_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