I want to take data that contains time gaps as well as time repeats and basically create a time series using the first occurrence of any given time and filling forwards. Consider the following example.
Lets say this is the time range we are interested in:
| Time |
|---|
| 1:00 |
| 1:01 |
| 1:02 |
| 1:03 |
| 1:04 |
| 1:05 |
And this is the data, dataframe X, we would like to put into our time series:
| Occurance | Value |
|---|---|
| 1:00 | "R" |
| 1:03 | "G" |
| 1:03 | "L" |
| 1:03 | "P" |
| 1:03 | "T" |
| 1:05 | "S" |
And this is the Final Dataframe:
| Occurance | Value |
|---|---|
| 1:00 | "R" |
| 1:01 | "R" |
| 1:02 | "R" |
| 1:03 | "G" |
| 1:04 | "G" |
| 1:05 | "S" |
As you can see, in the Final Dataframe, 1:00 has the value "R" because that is the value in the first occurrence of 1:00 in dataframe X. 1:01 and 1:02 also have the value "R" because there is no data for those time instances in dataframe X and will therefore use the last valid value (which is the value for 1:00). 1:03 has the value "G" because, similar to the case with 1:00, "G" is the first value for 1:03 that we have in dataframe X. Since there is no value for 1:04 in dataframe X, 1:04 gets the last valid value, "G", in our resulting dataframe. Lastly, 1:05 will have the value "S" in our resulting dataframe as that is the value for the first occurrence of 1:05 in dataframe X.
What is the quickest way to accomplish this?