title: How to replace NaNs by preceding or next values in pandas DataFrame?
body: <p>Suppose I have a DataFrame with some <code>NaN</code>s:</p>
  
  <pre><code>&gt;&gt;&gt; import pandas as pd
  &gt;&gt;&gt; df = pd.DataFrame([[1, 2, 3], [4, None, None], [None, None, 9]])
  &gt;&gt;&gt; df
      0   1   2
  0   1   2   3
  1   4 NaN NaN
  2 NaN NaN   9
  </code></pre>
  
  <p>What I need to do is replace every <code>NaN</code> with the first non-<code>NaN</code> value in the same column above it. It is assumed that the first row will never contain a <code>NaN</code>. So for the previous example the result would be</p>
  
  <pre><code>   0  1  2
  0  1  2  3
  1  4  2  3
  2  4  2  9
  </code></pre>
  
  <p>I can just loop through the whole DataFrame column-by-column, element-by-element and set the values directly, but is there an easy (optimally a loop-free) way of achieving this?</p>