title: Python: Check if unique id exists in previous timestamp, if so, check timestamp before that (and so on)
body: <p>I have a giant table of data that looks like this.</p>
  <pre><code>ID    Name   Category   Discovery Date  Timestamp
  1     Alpha    Low         3/1/2020      7/1/2020
  1     Alpha    Low         4/7/2020      7/1/2020
  1     Alpha    Low         5/2/2020      7/1/2020
  2     Bravo    Medium      2/17/2020     7/1/2020
  2     Bravo    Medium      2/26/2020     7/1/2020
  3     Charlie  Low         6/1/2020      7/1/2020
  1     Alpha    Low         5/2/2020      7/8/2020
  2     Bravo    Medium      2/17/2020     7/8/2020
  3     Charlie  Low         7/11/2020     7/15/2020
  </code></pre>
  <p>I am trying to insert a column between <em>Discovery Date</em> and <em>Timestamp</em> called <em>Target Date</em> that adds 90 days if <em>Category</em> == 'Low' and 30 days if <em>Category</em> == 'Medium' AND uses the earliest <em>Discovery Date</em> within a given <em>Timestamp</em> for all records with the same <strong>ID</strong>. However, a caveat is that if a specific <strong>ID</strong> was in the previous timestamp (current period - 1), I need to keep checking each previous timestamp until that <strong>ID</strong> does not show up in the previous timestamp, and then the earliest <em>Discovery Date</em> and <em>Category</em> logic can be used to determine the <em>Target Date</em>. Thus, the calculated field should look like this:</p>
  <pre><code>ID    Name   Category   Discovery Date     Target Date       Timestamp
  1     Alpha    Low         3/1/2020         5/30/2020        7/1/2020  
  1     Alpha    Low         4/7/2020         5/30/2020        7/1/2020  
  1     Alpha    Low         5/2/2020         5/30/2020        7/1/2020  
  2     Bravo    Medium      2/17/2020        3/18/2020        7/1/2020  
  2     Bravo    Medium      2/26/2020        3/18/2020        7/1/2020  
  3     Charlie  Low         6/1/2020         8/30/2020        7/1/2020  
  1     Alpha    Low         5/2/2020         5/30/2020        7/8/2020   
  2     Bravo    Medium      2/17/2020        3/18/2020        7/8/2020  
  3     Charlie  Low         7/11/2020        10/9/2020        7/15/2020
  </code></pre>
  <p>I believe some sort of recursive function to start at the latest (in above example, 7/15/2020) <em>Timestamp</em> is needed to check if a specific <strong>ID</strong> is in previous timestamp. If that is satisfied, check previous timestamp for that <strong>ID</strong> and so on and so forth. Once logic fails, and <strong>ID</strong> is no longer in previous timestamp, then you can use the earliest <em>Discovery Date</em> and <em>Category</em> logic.</p>