title: Update values in rows with null values in dummy dataframe
body: <p>I'm trying to update values of a Pandas dataframe inside a for loop. The dataframe consists of dummy categorical columns (i.e., the original categorical variables have converted to 0-1 for each possible category). Then, I'd like to update the rows referring to original null values, from this:</p>
  <pre><code>Feat1-valA   Feat1-valB   Feat1-NaN   Feat2-valC   Feat2-valD   Feat2-NaN
  1            0            0           1            0            0
  0            1            0           1            0            0
  0            0            1           1            0            0
  0            1            0           0            0            1
  0            0            1           0            0            1
  </code></pre>
  <p>to this:</p>
  <pre><code>Feat1-valA   Feat1-valB   Feat1-NaN   Feat2-valC   Feat2-valD   Feat2-NaN
  1            0            0           1            0            0
  0            1            0           1            0            0
  nan          nan          1           1            0            0
  0            1            0           nan          nan          1
  nan          nan          1           nan          nan          1
  </code></pre>
  <p>For if it is of any help, I'm attaching an image of some data values that should be updated to Nan:
  <a href="https://i.stack.imgur.com/r5U1J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r5U1J.png" alt="enter image description here" /></a></p>
  <p>To do that, I've tried the following piece of code:</p>
  <pre><code># Get the name of all the dummy columns for null values
  nan_cols_names = [col for col in dummies.columns if &quot;nan&quot; in col]
  
  # For each of those columns, tell if they have non-zero values (i.e., if the original non-dummy column actually has &quot;nan&quot; values)
  nan_cols_mask = dummies[nan_cols_names].sum() &gt; 0
  
  # List the dummy columns pertaining to features that have &quot;nan&quot; values
  nan_cols_true = list(nan_cols_mask[nan_cols_mask == True].index)
  
  # Display the number of &quot;nan&quot; values in each of these columns
  display(dummies[nan_cols_true].sum())
  
  for feature_nan in nan_cols_true:
      
      # Get the general label (remove &quot;_nan&quot;)
      feature_label = feature_nan[:-4]
      
      # Get the columns of the feature, except the &quot;_nan&quot; column
      feature_cols = [col for col in dummies.columns if feature_label in col][:-1]
      
      # Update the values of the non-&quot;_nan&quot; columns of the feature to be null values (instead of 0's, as they currently are)    
      dummies.loc[dummies[feature_nan] == 1, feature_cols] = np.nan
      
  # Display the number of &quot;nan&quot; values in each of these columns
  display(dummies[nan_cols_true].sum())
  </code></pre>
  <p>However, I see that the values don't get updated. What am I doing wrong?</p>
  <p>Thanks everyone,</p>