Carry Forward the Thermostat Setting
Problem
You are given a DataFrame `thermostatlog` (loaded from `thermostatlog.csv`) with columns `reading_seq` (the order of the reading) and `target_temp`. Some `target_temp` values are missing (null) because the thermostat only logs a value when the setting changes.
Fill each missing `target_temp` with the most recent non-null value from an earlier reading (ordered by `reading_seq`). Return the columns `reading_seq` and `target_temp`, ordered by `reading_seq`.
Input data
Example rows — the live problem includes the full dataset.
| reading_seq | target_temp |
|---|---|
| 1 | Warm 72F |
| 2 | |
| 3 | |
| 4 | Eco 68F |
| 5 | Cool 65F |
Expected output
Your answer should return 6 rows with the columns reading_seq, target_temp.
Starter code (Pandas (Python))
import pandas as pd
def carry_forward_the_thermostat_setting(thermostatlog) -> pd.DataFrame:
# Your code here
return thermostatlogSolve 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