Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesData Science AppliedModule 2 · Cleaning & Feature Engineering · Recapmerge_asof for backward-join on timepredict50 / 104
+75 XP
Task
📝 **Question:** Predict the output bid list for the snippet above. 📋 Pick the right answer. 💡 **Hint:** Re-read the theory above if unsure.
Predict the output

Read the code carefully

import pandas as pd

trades = pd.DataFrame({
    'time': pd.to_datetime(['10:00:00', '10:00:05', '10:00:10']),
    'price': [100, 102, 101],
})
quotes = pd.DataFrame({
    'time': pd.to_datetime(['09:59:50', '10:00:03', '10:00:08']),
    'bid':  [99.5, 101.5, 100.5],
})

out = pd.merge_asof(trades, quotes, on='time', direction='backward')
print(out['bid'].tolist())

# direction='backward' → for each trade, take the latest quote whose
# time is AT or BEFORE the trade time.
# What does this print? Type your prediction.

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…