Python
All Top Python Interview Questions#42
Fuzzy Time Series Matching with merge_asof() in Pandas
HardGoogleInterview Question #42
Asked at GoogleGiven `trades` (trade_time, ticker, shares) and `quotes` (quote_time, ticker, bid_price), match each trade to the most recent quote available on or before the trade time using `pd.merge_asof()`.
Input Table: trades & quotes
3 rows preview| trade_time | ticker | shares | quote_time | bid_price |
|---|---|---|---|---|
| 2026-01-01 09:30:05 | AAPL | 100 | 2026-01-01 09:30:00 | 150 |
| 2026-01-01 09:31:00 | AAPL | 50 | 2026-01-01 09:30:30 | 150.25 |
| 2026-01-01 09:30:10 | MSFT | 30 | 2026-01-01 09:30:05 | 300 |
Expected Output Structure3 rows
| trade_time | ticker | shares | quote_time | bid_price |
|---|---|---|---|---|
| 2026-01-01 09:30:05 | AAPL | 100 | 2026-01-01 09:30:00 | 150 |
| 2026-01-01 09:30:10 | MSFT | 30 | 2026-01-01 09:30:05 | 300 |
| 2026-01-01 09:31:00 | AAPL | 50 | 2026-01-01 09:30:30 | 150.25 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
Python 3.10 (Pandas)
Environment Ready
Starting the real Python + pandas runtime (one-time download)…