Flag Xbox Sign-In Dips Against a Rolling Hourly Baseline in Pandas

Last updated: November 29, 2026

Quick Overview

Given a DataFrame of Xbox sign-in events (user_id, timestamp), compute distinct active users per hour with missing hours filled as zero, compare each hour to the mean of the previous 24 hours, and flag hours that fall below half of that baseline.

Microsoft
Data Manipulation (SQL/Python)
Data Scientist
Microsoft
November 29, 2026
Data Scientist
Take-home Project
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given a DataFrame of Xbox sign-in events (user_id, timestamp), compute distinct active users per hour with missing hours filled as zero, compare each hour to the mean of the previous 24 hours, and flag hours that fall below half of that baseline.

A pandas exercise in the style of Microsoft gaming and service health data science work, where a sudden drop in sign-ins is often the first sign of an outage. The interviewer checks correct resampling with gap filling, a baseline that does not include the hour being tested, and sensible handling of the warm-up period.

What the Interviewer Expects
  • Parse timestamps to timezone-aware datetimes
  • Count distinct users per hour, not events
  • Reindex to a complete hourly range so silent hours become zero
  • Shift before rolling so the current hour is excluded from its own baseline
  • Leave the first 24 hours unflagged rather than comparing to partial windows
Key Topics to Cover
pandas
resampling
rolling windows
anomaly detection
time series
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 account for daily and weekly seasonality instead of a flat 24-hour mean?
  • How would you make this robust to a single spike hour inflating the baseline?
  • How would you run this every five minutes on streaming 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

events has columns user_id and ts, one row per sign-in, unsorted, possibly with many rows per user per hour. Timestamps may be strings or naive datetimes; I will treat them as UTC. "Active users...

Approach
  1. Bucket by hour with pd.Grouper(freq="h") and take nunique of user_id.
  2. Reindex to a complete hourly date_range with fill_value=0, so missing hours exist and count as zero.
  3. Baseline: ...

Submit Your Answer
Markdown supported