1 回答

TA貢獻1966條經驗 獲得超4個贊
嘗試:
df[df.groupby((df.status.shift().bfill().ne(df.status) & df.status.eq('OPEN')).cumsum()).transform(min).value.ge(70)]
結果:
status value
timestamp
2017-01-01 12:01:00 OPEN 83
2017-01-01 12:02:00 OPEN 82
2017-01-01 12:03:00 OPEN 87
2017-01-01 12:04:00 CLOSE 82
2017-01-01 12:05:00 CLOSE 81
2017-01-01 12:06:00 CLOSE 81
2017-01-01 12:07:00 CLOSE 81
2017-01-01 12:08:00 CLOSE 81
2017-01-01 12:09:00 CLOSE 81
2017-01-01 12:10:00 CLOSE 81
2017-01-01 12:11:00 CLOSE 81
2017-01-01 12:24:00 OPEN 87
2017-01-01 12:25:00 OPEN 87
2017-01-01 12:26:00 OPEN 87
2017-01-01 12:27:00 OPEN 87
2017-01-01 12:28:00 OPEN 87
2017-01-01 12:29:00 CLOSE 75
2017-01-01 12:30:00 CLOSE 75
2017-01-01 12:31:00 CLOSE 75
方法是創建status不等于前一個的組status,從 開始status == 'OPEN'。
然后保留value每組大于或等于 70 的行。
添加回答
舉報