AnalystPath

Solar Installer Three-Month Rolling Averages (2021)

PandasHardSenior level~10 min

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.

installers
installer_idonboarded_on
102020-12-10
82021-01-13
52021-02-16
72021-03-08
42021-05-17
requests
request_idhousehold_idrequested_on
6752020-12-09
1542021-02-09
10632021-03-04
19392021-04-06
3412021-06-03
bookings
request_idinstaller_idpanel_countjob_minutes
10106338
13107396
7810028
17711968
20112192

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 installers

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