title: How can I find the previous row in a DataFrame with a Timestamp index?
body: <p>I want to zero the last NaN at the start of a DataFrame in Pandas. My DataFrame objects have timestamps in.</p>
  
  <p><strong>Example data</strong></p>
  
  <p>If I have this data:</p>
  
  <pre><code>In [228]: my_df
  Out[228]: 
              blah
  1990-01-01   NaN
  1990-01-02   NaN
  1990-01-03   NaN
  1990-01-04   NaN
  1990-01-05   NaN
  1990-01-06     5
  1990-01-07     6
  1990-01-08     7
  1990-01-09   NaN
  1990-01-10     9
  
  [10 rows x 1 columns]
  </code></pre>
  
  <p>I want to get the following (changing the value on the 5th of January):</p>
  
  <pre><code>            blah
  1990-01-01   NaN
  1990-01-02   NaN
  1990-01-03   NaN
  1990-01-04   NaN
  1990-01-05     0
  1990-01-06     5
  1990-01-07     6
  1990-01-08     7
  1990-01-09   NaN
  1990-01-10     9
  
  [10 rows x 1 columns]
  </code></pre>
  
  <p><strong>What I've tried</strong></p>
  
  <p>I can get the index after the last NaN:</p>
  
  <pre><code>In [229]: ts = my_df['blah'].first_valid_index()
  
  In [230]: ts
  Out[230]: Timestamp('1990-01-06 00:00:00', tz=None)
  </code></pre>
  
  <p>I've found this ugly approach:</p>
  
  <pre><code>my_df['blah'][:ts][-2] = 0
  </code></pre>
  
  <p>However, this will throw <code>IndexError</code> if my DataFrame doesn't have any NaNs at the start. What would a better solution look like (presumably without just writing a for loop)?</p>