Python
#42

Fuzzy Time Series Matching with merge_asof() in Pandas

HardGoogle
Interview Question #42
Asked at Google

Given `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_timetickersharesquote_timebid_price
2026-01-01 09:30:05AAPL1002026-01-01 09:30:00150
2026-01-01 09:31:00AAPL502026-01-01 09:30:30150.25
2026-01-01 09:30:10MSFT302026-01-01 09:30:05300
Expected Output Structure3 rows
trade_timetickersharesquote_timebid_price
2026-01-01 09:30:05AAPL1002026-01-01 09:30:00150
2026-01-01 09:30:10MSFT302026-01-01 09:30:05300
2026-01-01 09:31:00AAPL502026-01-01 09:30:30150.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)…

Chat with us