Solar Installer Three-Month Rolling Averages (2021)
Problem
Same three DataFrames as the other solar-installer problems: `installers`, `requests` (`request_id`, `household_id`, `requested_on`), and `bookings` (`request_id`, `installer_id`, `panel_count`, `job_minutes`).\n\nFirst total, per 2021 month, the `panel_count` and `job_minutes` of all bookings whose request was made that month (a month with no bookings totals 0). Then restrict to **months 1 through 10** and, within that range, compute a forward three-month rolling average over the current month and the next two: `avg_panel_count` and `avg_job_minutes`, each rounded to **two decimals**. The window never reaches past month 10, so months 9 and 10 average only the months that remain inside 1-10.\n\nReturn columns `month` (1-10), `avg_panel_count`, `avg_job_minutes`. Rows may be in any order.
Input data
Example rows — the live problem includes the full dataset.
| installer_id | onboarded_on |
|---|---|
| 10 | 2020-12-10 |
| 8 | 2021-01-13 |
| 5 | 2021-02-16 |
| 7 | 2021-03-08 |
| 4 | 2021-05-17 |
| request_id | household_id | requested_on |
|---|---|---|
| 6 | 75 | 2020-12-09 |
| 1 | 54 | 2021-02-09 |
| 10 | 63 | 2021-03-04 |
| 19 | 39 | 2021-04-06 |
| 3 | 41 | 2021-06-03 |
| request_id | installer_id | panel_count | job_minutes |
|---|---|---|---|
| 10 | 10 | 63 | 38 |
| 13 | 10 | 73 | 96 |
| 7 | 8 | 100 | 28 |
| 17 | 7 | 119 | 68 |
| 20 | 1 | 121 | 92 |
Expected output
Your answer should return 10 rows with the columns month, avg_panel_count, avg_job_minutes.
Starter code (Pandas (Python))
import pandas as pd
def solar_rolling_avg(installers, requests, bookings) -> pd.DataFrame:
# Your code here
return installersSolve 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