title: Lambda apply include NaN values in new column
body: <p>I am creating a new column in a dataframe based on a conditional function. In the column I am mapping from, there are multiple NaN values. If a NaN value is present in the original column, I also want this to be present in my new column. As an example, my starting point is this:</p>
  
  <pre><code>Original
  0   1
  1   2
  2   3
  3   4
  4   5
  5   6
  6   Nan
  7   8
  8   9
  9   10
  </code></pre>
  
  <p>Here is a sample of the code I initially run which gives the following result (clearly):</p>
  
  <pre><code>def get_value(range):
      if range &lt; 2:
          return 'Below 2'
      elif range &lt; 8:
          return 'Between 2 and 8'
      else:
          return 'Above 8'
  
  df_sample['new_col'] = df_sample.apply(lambda x: get_value(x['Original']), axis=1)
  
  </code></pre>
  
  <pre><code>Original    new_col
  0   1.0 Below 2
  1   2.0 Between 2 and 8
  2   3.0 Between 2 and 8
  3   4.0 Between 2 and 8
  4   5.0 Between 2 and 8
  5   6.0 Between 2 and 8
  6   NaN Above 8
  7   8.0 Above 8
  8   9.0 Above 8
  9   10.0    Above 8
  
  </code></pre>
  
  <p>Here, index 6 should show NaN. </p>
  
  <p>I have tried including elif range == np.Nan: in my function but this didn't work. </p>
  
  <p>I then tried the following based on a recommendation on Stackoverflow:</p>
  
  <pre><code>df_sample['new_col'] = df_sample.apply(lambda x: get_value(x) if(np.all(pd.notnull(x['Original']))) else x, axis = 1)
  
  </code></pre>
  
  <p>But this returns an error at the first NaN index in my dataframe. </p>