title: Add new row based on an if condition via Python
body: <p>I need to add a new row if two consecutive cells of the column <code>door</code> are the same and the difference between two consecutive cells in the column <code>time</code> is more than 5 minutes.
  <strong>df:</strong></p>
  
  <pre><code>Time        door             name
  09:10:00    RDC_OUT-1        alex
  09:10:00    RDC_OUT-1        alex
  11:23:00    RDC_IN-1         alex
  12:13:00    RDC_IN-1         alex
  12:39:00    RDC_OUT-1        alex
  15:23:00    RDC_IN-1         alex
  </code></pre>
  
  <p><strong>Code</strong> :</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  file_name='test.xlsx'
  from datetime import timedelta
  import datetime
  
  df = pd.read_excel(file_name, header=0, index= False)
  df= df.sort_values(by='Time')
  df.reset_index(inplace = True) 
  
  print(df)
  
  idx=[]
  for i in range (0,len(df)):
      if i == 0:
          print ('Door Name '+str(i)+' ok')
      elif df['Door Name'][i] != df['Door Name'][i-1]:
          print('index '+str(i)+' ok')
  
      elif ((df['Door Name'][i] == df['Door Name'][i-1]) &amp; ((df['Time'].iloc[i] - df['Time'].iloc[i-1]) &gt; datetime.timedelta(minutes=5))):
          print('index '+str(i)+' ok')
          df.iloc[i] = [i,'RDC_OUT-1', str('12:00:00'), 'ARYA'] 
  
  
  
      elif ((df['Door Name'][i] == df['Door Name'][i-1]) &amp; ((df['Time'].iloc[i] - df['Time'].iloc[i-1]) &lt; datetime.timedelta(minutes=5))):
          print('index '+str(i)+' nok')
          idx.append(i)
          print('idx\n',idx)
  
  df.drop(df.index[[idx]],inplace=True)
  print('\n',df) 
  </code></pre>
  
  <p><strong>Desired output:</strong></p>
  
  <pre><code>Time        door              name
  Time        door             name
  09:10:00    RDC_OUT-1        alex
  11:23:00    RDC_IN-1         alex
  12:00:00    RDC_OUT-1        ARYA
  12:13:00    RDC_IN-1         alex
  12:39:00    RDC_OUT-1        alex
  15:23:00    RDC_IN-1         alex
  </code></pre>
  
  <p><strong>output</strong></p>
  
  <pre><code>0      4  09:10:00    RDC_OUT-1   alex
  2      3  11:23:00    RDC_IN-1    alex
  3      2  12:13:00    RDC_IN-1    alex
  4      3  12:00:00    RDC_OUT-1   ARYA
  5      0  15:23:00    RDC_IN-1    alex
  </code></pre>