Merging
Time series often go down to the second or even more granular, meaning that it can be difficult to merge if the entries don't have the same datetime. Pandas solves this problem with two additional merging functions. When we want to pair up observations that are close in time, we can use pd.merge_asof() to match on nearby keys rather than on equal keys, like we did with joins. On the other hand, if we want to match up the equal keys and order the keys without matches, we can use pd.merge_ordered().
To illustrate how these work, we are going to use the fb_prices and aapl_prices tables in the data/stocks.db SQLite database. These contain the price of Facebook and Apple stock, respectively, along with a timestamp of when the price was ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access