pandas 'int' 和 'Timestamp' 实例之间不支持截断“<”

pandas truncate '<' not supported between instances of 'int' and 'Timestamp'

我有以下代码:

import pandas as pd

t_start = pd.to_datetime('2022-02-14T06:32:54.332000')
t_end = pd.to_datetime('2022-02-14T06:35:24.880000')

lower = df.truncate(after=t_start).shape[0]-1
upper = df.truncate(after=t_end).shape[0]+1
# resample and return subset between start and end
selection = df.iloc[lower:upper, :]
selection_resampled = selection.resample(str(10) + 'ms').ffill()

目标是resample/upsample时间序列数据框的选择范围。但是出于什么原因,我收到消息

'<' not supported between instances of 'int' and 'Timestamp'

(计算下限和上限)

使用:

import pandas as pd

df = pd.DataFrame({'d':pd.date_range('2022-02-14T06:20:54.332000', '2022-02-14T06:50:54.332000', periods = 10)})
t_start = pd.to_datetime('2022-02-14T06:32:54.332000')
t_end = pd.to_datetime('2022-02-14T06:35:24.880000')
df[(df['d']<t_end)&(df['d']>t_start)]

输出:

然后你可以做其他的事情。