title: sklearn - how to incorporate missing data when one-hot encoding
body: <p>I'm trying to keep rows in a dataset that contain missing data.</p>
  
  <p>When one-hot encoding a column (or multiple columns) with sklearn. Is it possible to write a rule that <code>if currentItem == null</code> or <code>if currentItem == 0</code> then set the output array to all 0s?</p>
  
  <p>e.g.</p>
  
  <p><code>A    A    B</code>  -> <code>[[1, 0], [1, 0], [0,1]]</code></p>
  
  <p><code>B    B    A</code>  -> <code>[[0, 1], [0, 1], [1,0]]</code></p>
  
  <p><code>null B    A</code> -> <code>[[0, 0], [0, 1], [1,0]]</code></p>
  
  <hr>
  
  <p>one-hot encoding:</p>
  
  <pre><code>import numpy as np
  from sklearn.preprocessing import LabelEncoder
  
  
  dataset = np.loadtxt("someFile.csv", delimiter=",")
  B = dataset[:,1]
  
  encoder = LabelEncoder()
  encoder.fit(B)
  encoded_B = encoder.transform(B)
  
  Y = to_categorical(encoded_B)
  </code></pre>
  
  <p><strong>EDIT - Example Dataset:</strong>
  Where A-E are inputs and X &amp; Y and outputs</p>
  
  <pre><code>A     B     C     D     E     X      Y
  7     6     3     3     2     11     4
  5     6     0     0     7     15     7
  3     3     9     null  7     12     7
  7     null  7     null  7     12     13
  null  7     4     6     12    13     4
  null  5     7     6     null  14     7
  2     6     0     0     2     13     3
  7     null  7     null  2     13     7
  </code></pre>