Resample Irregular Nest Thermostat Readings Into Hourly Series in Pandas
Last updated: November 29, 2026
Quick Overview
Nest thermostats report temperature on change, at irregular times. Resample each device's readings into an hourly table with the hourly mean, reading count, and an end-of-hour state that forward fills at most two quiet hours.
0
0
0 solved
Nest thermostats report temperature on change, at irregular times. Resample each device's readings into an hourly table with the hourly mean, reading count, and an end-of-hour state that forward fills at most two quiet hours.
A Google Nest style IoT data question that checks resample semantics: what a bucket label means, how mean differs from last, and how far forward filling is trustworthy for event-driven sensors. Interviewers in Google's data take-homes like seeing explicit choices on missing data rather than a blanket ffill.
What the Interviewer Expects
- Use resample per device on a timestamp index
- Distinguish hourly mean of readings from end-of-hour state
- Forward fill with a limit and flag filled hours
- Handle time zones explicitly
- Explain why unlimited forward fill is dangerous for offline devices
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you compute a time-weighted average temperature for each hour?
- A device goes offline for two days. How should the dashboard show it?
- How would you do this across 50 million devices?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
readings(device_id, ts, temp_c), sent when temperature changes by some threshold and on a periodic heartbeat. Timestamps are UTC. For each device and hour I want the mean of readings in that hour, h...
Approach
Per device, set ts as the index and resample('h'). Each bucket labeled 10:00 covers 10:00 to 10:59. mean() averages readings inside the bucket and is NaN if there were none; last() is the late...