merge_asof question

62 views
Skip to first unread message

Peter Trinh

unread,
Dec 9, 2016, 3:40:10 PM12/9/16
to PyData
Hi,

Is there a function similar to merge_asof that selects the first row in the right DF whose 'on' key is greater than (or equal to) the left key?

Thank you,
Peter

Christopher Aycock

unread,
Dec 14, 2016, 2:26:04 PM12/14/16
to PyData
Off the top of my head, you could get the indices you want with

np.searchsorted(right['timestamp'].values, left['timestamp'].values)

This will return one-past-the-end for non-matching timestamps, so you can't directly use these indices with .iloc[] if there would be missing rows.

Christopher Aycock

unread,
Dec 15, 2016, 11:06:55 AM12/15/16
to PyData
I've just added this as a new request:

Peter Trinh

unread,
Dec 19, 2016, 9:31:00 AM12/19/16
to PyData
search sorted has been useful, but definitely looking forward to the merge_asof update.  Thank you for adding it as a new request Christopher.  

Peter
Reply all
Reply to author
Forward
0 new messages