Given the following dataframe:
data = [['2019-06-20 12:28:00', '05123', 2, 8888],
['2019-06-20 13:28:00', '55874', 6, 8888],
['2019-06-20 13:35:00', '12345', 1, 8888],
['2019-06-20 13:35:00', '35478', 2, 1234],
['2019-06-20 13:35:00', '12345', 2, 8888],
['2019-06-20 14:22:00', '98765', 1, 8888]]
columns = ['pdate', 'station', 'ptype', 'train']
df = pd.DataFrame(data, columns = columns)
where 'pdate'= passage time, 'station' = station code, 'ptype' = passage type and 'train' = train number
'ptype' can have following values (1=Arrival, 2=Departure, 6=Pass)
This is the result:
pdate station ptype train
0 2019-06-20 12:28:00 05123 2 8888
1 2019-06-20 13:28:00 55874 6 8888
2 2019-06-20 13:35:00 12345 1 8888
3 2019-06-20 13:35:00 35478 2 1234
4 2019-06-20 13:35:00 12345 2 8888
5 2019-06-20 14:22:00 98765 1 8888
Unfortunately sometimes at the station by mistake instead of registering 'ptype"=6 (Pass) they enter 'ptype"=1 (Arrival) AND 'ptype"=2 (Departure) happening on the SAME TIME. So those 2 records I have to consider as being just a single Pass record
I have to drop from the dataframe every rows having ptype=6 OR (ptype=1 AND the next record for the same station's and same train number's ptype=2 was happening exactly at the same time)
So from the given example I have to delete the following rows(1, 2, 4)
I have no problem to drop all rows where ptype = 6
df = df.drop(df[(df['ptype']==6)].index)
But I don't know how to delete the other pairs. Any idea?