设置为使用
df.between_time
,将其设置为DatetimeIndex,并添加任何您想要的可选过滤器:
df.timestamp = pd.to_datetime(df.timestamp)
df = df.set_index('timestamp')
threshold = 700
out = df.between_time('01:00', '02:00')[lambda x: x.y < threshold]
print(out)
y
timestamp
2019-08-01 01:00:00 608.0
2019-08-01 01:15:00 692.0
2019-08-01 01:45:00 692.0
2019-08-01 02:00:00 672.0
out.resample('d').first()
# Output:
y
timestamp
2019-08-01 608.0
df.timestamp = pd.to_datetime(df.timestamp)
df = (df.set_index('timestamp')
.between_time('18:00', '05:00')
[lambda x: x.y < threshold]
.resample('d')
.first())