title: pandas replace 0s with a value returned by a function
body: <p>I have a bunch of zeros in my pandas dataframe. I'd like to replace them with a value returned by a function. I am doing something similar using <code>fillna</code>. Here's a simplified version of my code for reproducibility:</p>
  <pre><code>import pandas as pd
  import numpy as np
  
  def replace(x):
      v = x * 2
      return v
  
  df = pd.DataFrame({'col1': [1,np.nan,0],
                     'col2': [1,2,3]
                   })
  
  df['col1'].replace(0, value returned by replace function)
  </code></pre>
  <p>Ideally, I'd like use lambda to do this. Here's how I am doing this for NaNs:</p>
  <pre><code>df['col1'].fillna(df.apply(lambda x: replace(x.col2), axis=1), inplace=True)
  </code></pre>