This question evaluates proficiency in data manipulation and temporal reasoning, specifically the competencies involved in sliding-window aggregation and merging overlapping or contiguous time intervals using pandas/SQL techniques.
You are given two independent pandas tasks.
df
has columns:
row_id
INT: unique row order
value
FLOAT: numeric value
row_id
.
k >= 0
, create a new column
window_avg
such that for row
i
:
window_avg(i) = average(value[i-k], ..., value[i], ..., value[i+k])
k
previous rows and
k
later rows.
k
rows and the last
k
rows, set
window_avg = -1
.
window_avg
.
events
has columns:
vehicle_id
STRING
start_ts
TIMESTAMP
end_ts
TIMESTAMP
vehicle_id
, merge intervals that overlap or touch, meaning
next.start_ts <= current.end_ts
.
vehicle_id
merged_start_ts
merged_end_ts
start_ts <= end_ts
for every row.