AnalystPath

Three-Day Rolling Average of Solar Output

PandasMediumMid level~10 min

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_output
panel_idkwhoutput_date
1102024-07-01
1202024-07-02
1302024-07-03
1602024-07-04
21002024-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_output

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