I have a series,
pd.Series( [6.22, 6.23, 6.23, 6.24, 6.24, 6.25, np.nan, np.nan, np.nan, np.nan], index = pd.DatetimeIndex(['2023-08-01 10:31:40.110000', '2023-08-01 10:31:43.110000',
'2023-08-01 10:31:46.111000', '2023-08-01 10:31:49.111000',
'2023-08-01 10:31:52.111000', '2023-08-01 10:31:55.117000',
'2023-08-01 10:31:58.112000', '2023-08-01 10:32:01.112000',
'2023-08-01 10:32:04.117000', '2023-08-01 10:34:07.095000'],
dtype='datetime64[ns]', name='exchange_time', freq=None))
referring to this python pandas dataframe resample.last how to make sure data comes from the same row
but,
ts.resample('6S', closed='left', label='right').apply(lambda x: x.iloc[-1])
gives error, because my time index has a big gap, how to solve this? thanks.
Note:
2023-08-01 10:32:00
should be resampled as NaN
as I always want the previous value no matter it is null or not. so .last()
won't work.