I have a data frame consists of column 1 i.e event and column 2 is Datetime:
Sample data
Event Time
0 2020-02-12 11:00:00
0 2020-02-12 11
Assuming the dataframe is data
:
current_event = None
result = []
for event, time in zip(data['Event'], data['Time']):
if event != current_event:
if current_event is not None:
result.append([current_event, start_time, time])
current_event, start_time = event, time
data = pandas.DataFrame(result, columns=['Event','EventStartTime','EventEndTime'])
The trick is to save your event number; if the next event number is not the same as the saved one, the saved one has to be ended and a new one started.