I have measurement data with 10 minutes interval. The thing is sometimes the time interval is 9min 59 seconds , or 10min 01 seconds and sometimes I have a missing value, so the time interval is 20 min.
What I want the code to do is the following: resample for 10min values (which I already implemented). The thing is, the measurements with interval other than 10:00 minutes (the 9min 59secs or 10min 01secs) are lost and I would like to keep this data.
Here is my testing code:
import pandas as pd
import numpy as np
df = pd.DataFrame(columns=('Datetime','V_L1','V_H3_L1','V_H3_L1_in_P'))
df['Datetime'] = ['01.01.2012 00:00:00', '01.01.2012 00:10:01', '01.01.2012 00:29:59','01.01.2012 00:50:00']
df['V_L1'] = [219,219.7,np.nan,220.3]
df['V_H3_L1'] = [3,1,2.5, np.nan]
df['Datetime'] = pd.to_datetime(df['Datetime'])
df.set_index('Datetime')
df = df.set_index('Datetime').resample('600S').asfreq()
Output:
V_L1 V_H3_L1 V_H3_L1_in_P
Datetime
2012-01-01 00:00:00 219.0 3.0 NaN
2012-01-01 00:10:00 NaN NaN NaN
2012-01-01 00:20:00 NaN NaN NaN
2012-01-01 00:30:00 NaN NaN NaN
2012-01-01 00:40:00 NaN NaN NaN
2012-01-01 00:50:00 220.3 NaN NaN
Wished output:
V_L1 V_H3_L1 V_H3_L1_in_P
Datetime
2012-01-01 00:00:00 219.0 3.0 NaN
2012-01-01 00:10:00 219.7 1.0 NaN
2012-01-01 00:20:00 NaN NaN NaN
2012-01-01 00:30:00 NaN 2.5 NaN
2012-01-01 00:40:00 NaN NaN NaN
2012-01-01 00:50:00 220.3 NaN NaN
So I want to keep the data like accepting if the delta from the frequency set (10min, 600s) is smaller than some seconds + or - 5 seconds.