Three-Day Rolling Average of Solar Output
Problem
DataFrame `panel_output` has columns `panel_id`, `kwh`, and `output_date`. For each panel, compute a three-day rolling average of `kwh` ordered by date, but only keep a window when the three readings cover three consecutive calendar days (the day two positions back is exactly 2 days earlier). Round the average to 2 decimals.
Return columns `panel_id`, `output_date`, `avg_3day`, sorted by `panel_id` then `output_date`.
Input data
Example rows — the live problem includes the full dataset.
| panel_id | kwh | output_date |
|---|---|---|
| 1 | 10 | 2024-07-01 |
| 1 | 20 | 2024-07-02 |
| 1 | 30 | 2024-07-03 |
| 1 | 60 | 2024-07-04 |
| 2 | 100 | 2024-07-01 |
Expected output
Your answer should return 3 rows with the columns panel_id, output_date, avg_3day.
Starter code (Pandas (Python))
import pandas as pd
def rolling_solar_average(panel_output) -> pd.DataFrame:
# Your code here
return panel_outputSolve 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