There is a dataset containing 3000 rows and 5 columns as -
Id Tag_number Creation_time Code Alert_message
1 GH567 17:19.8 MEI001 0
2 GH567 58:33.4 MEI001 0
3 GH567 15:21.6 MEI001 1
4 GH567 59:33.7 MEI001 1
5 HR864 16:23.5 XUY056 0
6 KI964 34:13.6 UYT345 0
7 KI964 55:24.8 UYT345 1
.... 3000 rows
The dataset contains information on when alerts were created (known as 1) and when not created (as 0). Here the "Creation_time" shows both the date and time when alert was created. The ask is to extract rows based on condition applied to "Alert_message". The condition would be to check whenever there's a "0" occurring is there a "1" occurring consecutive to it in next row. If yes, extract both rows into another dataframe. The end result should look like -
Id Tag_number Creation_time Code Alert_message
2 GH567 58:33.4 MEI001 0
3 GH567 15:21.6 MEI001 1
6 KI964 34:13.6 UYT345 0
7 KI964 55:24.8 UYT345 1
I have used -
df1 = df[df.Alert_message.gt(0) | df.Alert_message.shift(-1).gt(0)]
The result I got -
Id Tag_number Creation_time Code Alert_message
2 GH567 58:33.4 MEI001 0
3 GH567 15:21.6 MEI001 1
4 GH567 59:33.7 MEI001 1
Would need some suggestions on this. Thanks and appreciate your time and effort!!