Resampling Dataframe In Pandas As A Checking Operation
Solution 1:
You can use the asfreq
method to produce evenly spaced indexes every 12 hours which will automatically put np.nan
values for every jump. Then you can just forward fill columns A and B.
df1= df.asfreq('12H')
df1[['A','B']] = df1[['A','B']].fillna(method='ffill')
Solution 2:
I would go for simply sorting your dataframe on the index and create a new column that takes the value from the next row (for the time). The current time would be called "from" and the time from the next time would be called "to".
Next step would be to use the two columns ("from" and "to") to create a column containing a list of values between this row and next row for every 12 hours (a range basically).
Final step would be to "explode" every line for each value in the range. Look at How to explode a list inside a Dataframe cell into separate rows
Hope this helps :)
Post a Comment for "Resampling Dataframe In Pandas As A Checking Operation"