title: Pandas: .apply function gives entire column single value
body: <p>Lets say I have the following dataframe:</p>
  
  <pre><code>ID  |  has_id_dummy
  -----------------------
   340         NaN
   NaN         NaN
   NaN         NaN
   200         NaN
  </code></pre>
  
  <p>And I want to turn it into this DataFrame:</p>
  
  <pre><code>     ID  |  has_id_dummy
      -----------------------
       340         1
       NaN         0
       NaN         0
       200         1
  </code></pre>
  
  <p>To do this I came up with the following function:</p>
  
  <pre><code>def dummypopulator(x):
      if x != np.nan:
          return 1
      return 0
  </code></pre>
  
  <p>which I call with the following line</p>
  
  <pre><code>df['has_id_dummy'] = df['ID'].apply(dummypopulator)
  </code></pre>
  
  <p>But the value is then set to 1 for all rows, even the rows that dont have an ID and should be 0. </p>
  
  <pre><code>     ID  |  has_id_dummy
      -----------------------
       340         1
       NaN         1
       NaN         1
       200         1
  </code></pre>
  
  <p>I tried calling the function with a seperate lambda as I saw in an example:</p>
  
  <pre><code>df['has_id_dummy'] = df['ID'].apply(lambda x: dummypopulator(x))
  </code></pre>
  
  <p>Yet the result is the same. </p>
  
  <p>I feel like I am missing a very obvious error, but for the life of me cant figure out why it wont work. Does anyone know what I am doing wrong?</p>