title: Pandas generate True/False column if term is in cell
body: <p>I have a column with values listed as a string, delimited with '; ' and I would like to generate true/false columns for each separate value. The dataframe is large (100k rows, 13 values) and my current code does around 1.5 rows per second in that dataframe. Is there a dedicated pandas function that would do this much faster? Or is there an obvious mistake I'm making that slows my code down impossibly?</p>
  
  <p>Data looks like:</p>
  
  <pre><code>   id      likes colour
  0   1              blue
  1   2  blue; green; red
  2   3       red; purple
  3   4      purple; blue
  4   5       yellow; red
  5   6            yellow
  </code></pre>
  
  <p>Output is:</p>
  
  <pre><code>   id      likes colour    red  yellow   blue  purple  green
  0   1              blue  False   False   True   False  False
  1   2  blue; green; red   True   False   True   False   True
  2   3       red; purple   True   False  False    True  False
  3   4      purple; blue  False   False   True    True  False
  4   5       yellow; red   True    True  False   False  False
  5   6            yellow  False    True  False   False  False
  </code></pre>
  
  <p>Current function to go from first  to second frame:</p>
  
  <pre><code>def do_thing(data, col_name = 'likes colour'):
      cols = list(set([j for i in list(data[col_name]) for j in i.split('; ')]))
      for i in cols:
          data[i] = None
      for i in data.index:
          for j in cols:
              if j in data.loc[i, col_name]:
                  data.loc[i, j] = True
              else:
                  data.loc[i, j] = False
      return data
  </code></pre>
  
  <p>Basically, this first identifies each different value, then creates empty columns for each and finally fills these with True or False there or not a given word is there.</p>
  
  <p>It's fine for the sample dataframe, but once I add a few more colors and multiply by 10000 it goes at a snail's pace. Help is much appreciated!</p>