title: Comparing timedelta fields
body: <p>I am looking at file delivery times and can't work out how to compare two timedelta fields using a for loop if statement.</p>
  <p><code>time_diff</code> is the difference between <code>cob_date</code> and <code>last_update_time</code></p>
  <p><code>average_diff</code> is based on the average for a particular file</p>
  <p>I want to find the delay for each row.</p>
  <p>I have been able to produce a column <code>delay</code> using <code>average_diff - time_diff</code></p>
  <p>However, when the <code>average_diff - time_diff &lt; 0</code> I just want to return <code>delay = 0</code> as this is not a delay.</p>
  <p>I have made a for loop but this isn't working and I don't know why. I'm sure the answer is very simple but I can't get there.</p>
  <pre><code>test_pv_import_v2['delay2'] = pd.to_timedelta('0')
  
  for index, row in test_pv_import_v2.iterrows():
      if test_pv_import_v2['time_diff'] &gt; test_pv_import_v2['average_diff'] :
          test_pv_import_v2['delay2'] = test_pv_import_v2['time_diff'] - test_pv_import_v2['average_diff']
  </code></pre>
  <p><a href="https://i.stack.imgur.com/yljqI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yljqI.png" alt="enter image description here" /></a></p>