I'm using Pandas to process huge time series dataset. I would like add row between the rows in the dataframe if the difference between two consecutive indexes is greater than 5.
Actual:
a result
Date
1497544649 1 1.0
1497544652 9 1.0
1497544661 9 NaN
Expected:
a result
Date
1497544649 1 1.0
1497544652 9 1.0
1497544657 9 0
1497544661 9 NaN
I used diff() on index to get difference between two consecutive indexes but not sure how to insert record if the difference is greater than 5.
import pandas as pd
df = pd.DataFrame([{"Date": 1497544649,"a":1, "result": 1},
{"Date": 1497544652,"a": 9, "result": 1},
{"Date": 1497544661,"a": 9, "result": 1}])
df.set_index("Date", inplace=True)
df.index.to_series().diff().fillna(0).to_frame("diff")
Any pointers on how to achieve this would be appreciated
Thank you