I have a set of data that will remain static. I haven't determined the best format to store it yet, probably a DataFrame, but I'm open to suggestions.
My aim is to roll the data forward, so my static dataset is up to date, but I need to keep the days consistent. For example, if my static data looks like this:
Date Day Temp
0 01/01/2021 Fri 20
1 02/01/2021 Sat 17
2 03/01/2021 Sun 17
3 04/01/2021 Mon 16
4 05/01/2021 Tue 20
5 06/01/2021 Wed 16
6 07/01/2021 Thu 21
7 08/01/2021 Fri 19
The last data I will have is for 08/01/2021. If I were to run this data on 09/01/2021, it would look like:
Date Day Temp
0 02/01/2021 Sat 17
1 03/01/2021 Sun 17
2 04/01/2021 Mon 16
3 05/01/2021 Tue 20
4 06/01/2021 Wed 16
5 07/01/2021 Thu 21
6 08/01/2021 Fri 19
7 09/01/2021 Sat 17
The 09/01/2021 is a Saturday, so it rolled the data from the last Saturday in the dataset, 02/01/2021, forward.
I won't be able to determine ahead of time of many days the dataset will contain, and I may have to roll the data forward multiple times, for example, the last data in the static dataset might be 15/05/2018, and I need to roll it on to today.
I've looked at numpy roll and pandas shift, but I'm struggling to keep the days consistent.
Out of interest, it is possible to improve this even further. Rather than matching the oldest day and rolling it forward, it first tries to match on the oldest data with the same month and day - so that the monthly temperatures remain consistent?
Thanks
question from:https://stackoverflow.com/questions/66054997/roll-data-forward-in-python-keeping-the-days-consistent