title: Pandas accessing last non-null value
body: <p>I want to fill data frame NaNs with the last valid value for a given group. For instance:</p>
  
  <pre><code>import pandas as pd
  import random as randy
  import numpy as np
  
  df_size = int(1e1)                
  df = pd.DataFrame({'category': randy.sample(np.repeat(['Strawberry','Apple',],df_size),df_size), 'values': randy.sample(np.repeat([np.NaN,0,1],df_size),df_size)}, index=randy.sample(np.arange(0,10),df_size)).sort_index(by=['category'], ascending=[True])
  </code></pre>
  
  <p>Delivers: </p>
  
  <pre><code>     category   value
  7       Apple     NaN
  6       Apple       1
  4       Apple       0
  5       Apple     NaN
  1       Apple     NaN
  0  Strawberry       1
  8  Strawberry     NaN
  2  Strawberry       0
  3  Strawberry       0
  9  Strawberry     NaN
  </code></pre>
  
  <p>And the column I wish to calculate looks like this:</p>
  
  <pre><code>     category   value  last_value
  7       Apple     NaN         NaN
  6       Apple       1         NaN
  4       Apple       0           1
  5       Apple     NaN           0
  1       Apple     NaN           0
  0  Strawberry       1         NaN
  8  Strawberry     NaN           1
  2  Strawberry       0           1
  3  Strawberry       0           0
  9  Strawberry     NaN           0
  </code></pre>
  
  <p>Tried <code>shift()</code> and <code>iterrows()</code> but to no avail.</p>