title: How to get one hot encoding of specific words in a text in Pandas?
body: <p>Let's say I have a dataframe and list of words i.e</p>
  
  <pre><code>toxic = ['bad','horrible','disguisting']
  
  df = pd.DataFrame({'text':['You look horrible','You are good','you are bad and disguisting']})
  
  main = pd.concat([df,pd.DataFrame(columns=toxic)]).fillna(0)
  
  samp = main['text'].str.split().apply(lambda x : [i for i in toxic if i in x])
  
  for i,j in enumerate(samp):
      for k in j:
          main.loc[i,k] = 1 
  </code></pre>
  
  <p>This leads to : </p>
  
  <pre><code>   bad  disguisting  horrible                         text
  0    0            0         1            You look horrible
  1    0            0         0                 You are good
  2    1            1         0  you are bad and disguisting
  </code></pre>
  
  <p>This is bit faster than get_dummies, but for loops in pandas is not appreciable when there is  huge amount of data.</p>
  
  <p>I tried with <code>str.get_dummies</code>, this will rather one hot encode every word in the series which makes it bit slower. </p>
  
  <pre><code>pd.concat([df,main['text'].str.get_dummies(' ')[toxic]],1)
  
                            text  bad  horrible  disguisting
  0            You look horrible    0         1            0
  1                 You are good    0         0            0
  2  you are bad and disguisting    1         0            1
  </code></pre>
  
  <p>If I try the same in scipy.</p>
  
  <pre><code>from sklearn import preprocessing
  le = preprocessing.LabelEncoder()
  le.fit(toxic)
  main['text'].str.split().apply(le.transform)
  </code></pre>
  
  <p>This leads to <code>Value Error,y contains new labels</code>. Is there a way to ignore the error in scipy? </p>
  
  <p>How can I improve the speed of achieving the same, is there any other fast way of doing the same?</p>