Python & R: Merging Time Series Data
Rolling Forward Fill Merges in R and Python, and why you should do it too. Can also just use the function we build in there.
Required Readings:
Time Series analysis & Lookahead Bias
R & Python Programming (libraries)
Table of Contents:
Introduction
Rolling Forward Data (Re-sampling)
Merging Data
Rolling Merges
1 - Introduction
You can download the GAP data here:
You can download the Unemployment data here:
You can download the CPI data here:
Sometimes, we will have to pull chunks of data from multiple locations, and then merge them together to make a new dataset. There are a few different ways to do it, this post will focus on: merging data, doing forward fills, and doing them together.
Hence the emphasis on time series merging.
2 - Rolling Forward Data (Re-sampling)
Notice the FRED economic data is in a monthly format, but the stock data is in a daily format. Now, since I just grabbed the data directly from FRED instead of using the app I developed, to make it fair, I need to roll the FRED data forward about 1 month (at least). In other words the Date Jan 1, 2021 becomes Jan 31, 2021.
This is also known as re-sampling the data.
The stock data on the other hand is available on a daily basis, so we won’t need to roll that one forward, and can just keep it as is.
Python
To handle this one easily, we will create a new column called Ceiling_Date. To
Keep reading with a 7-day free trial
Subscribe to Data Science & Machine Learning 101 to keep reading this post and get 7 days of free access to the full post archives.