title: Replace NaN with a random value every row
body: <p>I have a dataset with a column 'Self_Employed'. In these columns are values 'Yes', 'No' and 'NaN. I want to replace the NaN values with a value that is calculated in calc(). I've tried some methods I found on here, but I couldn't find one that was applicable to me.
  Here is my code, I put the things i've tried in comments.:</p>
  
  <pre><code>    # Handling missing data - Self_employed
  SEyes = (df['Self_Employed']=='Yes').sum()
  SEno = (df['Self_Employed']=='No').sum()
  
  def calc():
      rand_SE = randint(0,(SEno+SEyes))
      if rand_SE &gt; 81:
          return 'No'
      else:
          return 'Yes'
  
  
  &gt; # df['Self_Employed'] = df['Self_Employed'].fillna(randint(0,100))
  &gt; #df['Self_Employed'].isnull().apply(lambda v: calc())
  &gt; 
  &gt; 
  &gt; # df[df['Self_Employed'].isnull()] = df[df['Self_Employed'].isnull()].apply(lambda v: calc())  
  &gt; # df[df['Self_Employed']]
  &gt; 
  &gt; # df_nan['Self_Employed'] = df_nan['Self_Employed'].isnull().apply(lambda v: calc())
  &gt; # df_nan
  &gt; 
  &gt; #  for i in range(df['Self_Employed'].isnull().sum()):
  &gt; #      print(df.Self_Employed[i]
  
  
  df[df['Self_Employed'].isnull()] = df[df['Self_Employed'].isnull()].apply(lambda v: calc())
  df
  </code></pre>
  
  <p>now the line where i tried it with df_nan seems to work, but then I have a separate set with only the former missing values, but I want to fill the missing values in the whole dataset. For the last row I'm getting an error, i linked to a screenshot of it.
  Do you understand my problem and if so, can you help?</p>
  
  <p><a href="https://i.stack.imgur.com/1RaW9.png" rel="nofollow noreferrer">This is the set with only the rows where Self_Employed is NaN</a></p>
  
  <p><a href="https://i.stack.imgur.com/uwT4g.png" rel="nofollow noreferrer">This is the original dataset</a></p>
  
  <p><a href="https://i.stack.imgur.com/GhRoC.png" rel="nofollow noreferrer">This is the error</a></p>