title: Return the last non-zero value in a panda df
body: <p>I have a dataframe</p>
  <pre><code>    col0 col1   col2 col3 col4
  0   1   3   6  6  0
  1   0   2   8  7  3
  2   0   0   4  3  4
  3   4   2   2  0  4
  </code></pre>
  <p>The logic is if col1 is not zero, return col1. If col 1 is zero, return col2 (non-zero). If col 2 is zero, return col3. We don't need to do anything for col4</p>
  <p>My code looks like below but it only returns col1</p>
  <pre><code>def test(df):
          if df['col1'].iloc[0] &gt; 0:
              return df['col1']
          elif df['col1'].iloc[0] == 0 &amp; df['col2'].iloc[0] &gt; 0:
              return df['col2']
          elif df['col2'].iloc[0]  == 0 &amp; df['col3'].iloc[0]  &gt; 0:
              return df['col3']
          else:
              return 0
  test(new)
  </code></pre>
  <p>I tried .any() and .all(), it doesnt work either. Also, is there anyway to make this piece of code more efficient?</p>