Skip to main content

Change time series frequency, ffill values until the next input but with a limit

I have data with timestamps, I want to make it into 1min time series and fill the missing values in rows that are created with the last input. However, also have a limit on the ffill function as well. So, if the next input is missing for too long, leave NaN.

Data:

timestamp           pay
2020-10-10 23:32    50
2020-10-11 21:55    80
2020-10-13 23:28    40  

Convert to this using df.set_index('timestamp').asfreq('1Min', method='ffill'), forward fill the pay column until the next input, but if the next input is more than 24 hours away (1440 rows), only fill up to 1440 rows.

So, 2020-10-11 21:55 80 should only filled with 80 until 2020-10-12 21:55 , then leave NaN until 2020-10-13 23:28 40.

How can I achieve this?



source https://stackoverflow.com/questions/74424457/change-time-series-frequency-ffill-values-until-the-next-input-but-with-a-limit

Comments