title: Retaining NaN values after get_dummies in Pandas
body: <p>I have a dataframe 'df' like this -</p>
  
  <pre><code>Id    v1    v2
  0     A     0.23
  1     B     0.65
  2     NaN   0.87
  </code></pre>
  
  <p>If I use</p>
  
  <pre><code>df1 = get_dummies(df)
  df1
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>Id    v1_A    v1_B    v2
  0     1       0       0.23
  1     0       1       0.65
  2     0       0       0.87 .
  </code></pre>
  
  <p>How can I get the following efficiently?</p>
  
  <pre><code>Id    v1_A    v1_B    v2
  0     1       0       0.23
  1     0       1       0.65
  2     NaN     NaN     0.87 .
  </code></pre>
  
  <p>I was using this initially, but it takes too long</p>
  
  <pre><code>import numpy as np    
  dfv1 = df[[v1]]    #Slicing the v1 column
  dfs = get_dummies(dfv1)    
  dfsum = dfs.apply(np.sum, axis=1)    #Calculating row by row sum of dfs
  for i in range(dfs.size):    #Iterating over the entire dataframe
      if dfsum.iloc[i]==0:     #and if the sum is zero for some 'i'
          dfs.iloc[i][:]==np.nan    #changing corresponding row to NaN
  del df['v1']    #Deleting original column
  df = pandas.concat([df, dfs], axis=1)    #Appending the new one
  </code></pre>
  
  <p>I am using Python 3.5.1 on Jupyter, and Pandas 0.18 . Thanks.</p>