Forward-Fill Sensor Gaps With a Limit Then Resample Hourly

Last updated: November 29, 2026

Quick Overview

Given minute-level sensor readings per asset with missing timestamps and null values, forward-fill gaps of at most N minutes (leaving longer outages empty) and return, per asset and hour, the average value and the count of valid minutes.

C3 AI
Data Manipulation (SQL/Python)
Data Scientist
C3 AI
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given minute-level sensor readings per asset with missing timestamps and null values, forward-fill gaps of at most N minutes (leaving longer outages empty) and return, per asset and hour, the average value and the count of valid minutes.

C3 AI data scientists spend much of their time cleaning historian data from pumps, compressors and transformers before any reliability model is trained. A screen like this checks that you can handle per-asset time series in pandas without leaking values across assets or silently papering over a real outage.

What the Interviewer Expects
  • Group by asset before filling so values never bleed from one asset into another
  • Reindex to a full minute grid so missing timestamps become explicit nulls
  • Use a bounded forward fill and explain why long gaps must stay missing
  • Report a valid-minute count alongside the mean so downstream code can judge coverage
  • Handle duplicate timestamps and unsorted input deliberately
Key Topics to Cover
pandas groupby
time series reindexing
bounded forward fill
resampling
data quality
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you mark which values were imputed so a model can use that as a feature?
  • When is linear interpolation better than forward fill for a sensor like temperature versus a valve state?
  • How would this change if readings arrive at irregular intervals instead of every minute?
  • How would you run this over 50,000 assets and two years of data?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

Input columns: asset_id, ts (minute resolution), value (float, may be null). A minute can be absent entirely or present with a null. I will assume the expected cadence is one reading per minute,...

Approach
  1. Parse and sort by asset then time.
  2. For each asset, reindex onto a complete 1-minute range so absent minutes become NaN.
  3. ffill(limit=max_gap) fills at most max_gap consecutive missing mi...

Submit Your Answer
Markdown supported

Related Questions