Annual Energy Output Growth by Panel Model
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.
| reading_id | panel_model | kwh | recorded_at |
|---|---|---|---|
| 1 | 100 | 200.00 | 2021-03-14 09:00:00 |
| 2 | 100 | 150.00 | 2021-08-02 11:30:00 |
| 3 | 100 | 400.00 | 2022-05-21 10:15:00 |
| 4 | 100 | 100.00 | 2022-09-09 14:00:00 |
| 5 | 200 | 300.00 | 2022-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_readingsSolve 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