title: pandas drop rows based on "neighbours"
body: <p>Given the following dataframe:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>where 'pdate'= passage time, 'station' = station code, 'ptype' = passage type and 'train' = train number</p>
  
  <p>'ptype' can have following values (1=Arrival, 2=Departure, 6=Pass)</p>
  
  <p>This is the result:</p>
  
  <pre><code>                 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
  </code></pre>
  
  <p>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</p>
  
  <p>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)</p>
  
  <p>So from the given example I have to delete the following rows(1, 2, 4)</p>
  
  <p>I have no problem to drop all rows where ptype = 6</p>
  
  <pre><code>df = df.drop(df[(df['ptype']==6)].index)
  </code></pre>
  
  <p>But I don't know how to delete the other pairs.
  Any idea?</p>