title: Find index of the first and/or last value in a column that is not NaN
body: <p>I am dealing with sub-surface measurements from a borehole where each measurement type covers a different range of depths.  Depth is being used as the index in this case.  </p>
  
  <p>I need to find the depth (index) of the first and/or last occurrence of data (non-NaN value) for each measurement type.</p>
  
  <p>Getting the depth (index) of the first or last row of the dataframe is easy: <code>df.index[0]</code> or <code>df.index[-1]</code>.  The trick is in finding the index of the first or last non-NaN occurrence of any given column.</p>
  
  <pre class="lang-py prettyprint-override"><code>df = pd.DataFrame([[500, np.NaN, np.NaN,     25],
                     [501, np.NaN, np.NaN,     27],
                     [502, np.NaN,     33,     24],
                     [503,      4,     32,     18],
                     [504,     12,     45,      5],
                     [505,      8,     38, np.NaN]])
  df.columns = ['Depth','x1','x2','x3']
  df.set_index('Depth')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Y7taF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y7taF.png" alt="enter image description here"></a></p>
  
  <p>The ideal solution would produce an index (depth) of 503 for the first occurrence of x1, 502 for the first occurrence of x2, and 504 for the last occurrence of x3.</p>