我的数据中存在NAN的线性内插问题.我有一些瞬时测量,我想从6分钟间隔重采样到5分钟间隔.
df = pd.DataFrame(zip(['10:00','10:06','10:12','10:18','10:24'],
[1, 2, 3, 0.5, 2.5], [0, np.nan, 5, 2.5, 10]),
columns=['date','column_a','column_b'])
df['date'] = pd.to_datetime(df['date'], infer_datetime_format=True)
df = df.set_index('date')
print(df)
column_a column_b
date
2023-07-19 10:00:00 1.0 0.0
2023-07-19 10:06:00 2.0 NaN
2023-07-19 10:12:00 3.0 5.0
2023-07-19 10:18:00 0.5 2.5
2023-07-19 10:24:00 2.5 10.0
我使用了这个代码,但在10:05应该是NaN而不是Value.谢谢你的帮助.
print(df.resample('1Min').interpolate(method='linear', limit=5).resample('5Min').asfreq())
column_a column_b
date
2023-07-19 10:00:00 1.000000 0.000000
2023-07-19 10:05:00 1.833333 2.083333 <--- here should be nan
2023-07-19 10:10:00 2.666667 NaN
2023-07-19 10:15:00 1.750000 3.750000
2023-07-19 10:20:00 1.166667 5.000000