title: How to drop all rows before a specific word except the last row in a dataframe to calculate the "delta"
body: <p>I have a dataframe containing [3599 rows x 5 columns]. I need to drop all rows before a specific word except the last row in a dataframe to calculate the &quot;delta&quot;. This is an example of the dataframe that I have: </p>
  <pre><code>df = 
               daytime       ProductCase       timestamp           delta 
   
  0     2020-01-01 00:00:01    Product  2020-01-01 00:00:01             NaT   
  
  1     2020-01-01 00:00:02    Product  2020-01-01 00:00:02 0 days 00:00:01   
  
  2     2020-01-01 00:00:03    Product  2020-01-01 00:00:03 0 days 00:00:01   
  
  3     2020-01-01 00:00:04    NoProduct  2020-01-01 00:00:04 0 days 00:00:01   
  
  4     2020-01-01 00:00:05    NoProduct  2020-01-01 00:00:05 0 days 00:00:01  
  
  5     2020-01-01 00:00:06    NoProduct  2020-01-01 00:00:06 0 days 00:00:01   
  
  6     2020-01-01 00:00:07    NoProduct 2020-01-01 00:00:07 0 days 00:00:01
  
  7     2020-01-01 00:00:08    Product  2020-01-01 00:00:08 0 days 00:00:01   
  
  8     2020-01-01 00:00:09    Product  2020-01-01 00:00:09 0 days 00:00:01   
  
  9     2020-01-01 00:00:10    NoProduct  2020-01-01 00:00:10 0 days 00:00:01  
  
  10     2020-01-01 00:00:11    NoProduct  2020-01-01 00:00:11 0 days 00:00:01   
  
  11     2020-01-01 00:00:12    NoProduct 2020-01-01 00:00:12 0 days 00:00:01 
  
  12     2020-01-01 00:00:13    NoProduct 2020-01-01 00:00:13 0 days 00:00:01 
  
  13     2020-01-01 00:00:14    NoProduct 2020-01-01 00:00:14 0 days 00:00:01 
  
        time  
  
  0      NaN  
  
  1      1.0  
  
  2      1.0  
  
  3      1.0  
  
  4      1.0  
  
  5      1.0  
  
  6      1.0  
  
  7      1.0
  
  8      1.0  
  
  9      1.0  
  
  10      1.0    
  
  11      1.0  
  
  12     1.0 
  
  13     1.0 
  </code></pre>
  <p>I would like to know how to drop out all rows containing &quot;NoProduct&quot; except the last row with calculating the delta to get the dataframe below.</p>
  <pre><code>             daytime       ProductCase       timestamp           delta  
  0     2020-01-01 00:00:01    Product  2020-01-01 00:00:01             NaT   
  
  1     2020-01-01 00:00:02    Product  2020-01-01 00:00:02 0 days 00:00:01   
  
  2     2020-01-01 00:00:03    Product  2020-01-01 00:00:03 0 days 00:00:01   
  
  3     2020-01-01 00:00:07    NoProduct 2020-01-01 00:00:07 0 days 00:00:04
  
  4     2020-01-01 00:00:08    Product  2020-01-01 00:00:08 0 days 00:00:01   
  
  5     2020-01-01 00:00:09    Product  2020-01-01 00:00:09 0 days 00:00:01   
  
  6     2020-01-01 00:00:14    NoProduct 2020-01-01 00:00:14 0 days 00:00:05 
  
  
        time  
  
  0      NaN  
  
  1      1.0  
  
  2      1.0  
  
  3      4.0  
  
  4      1.0  
  
  5      1.0  
  
  6      5.0  
  </code></pre>