title: Quickest way to make a get_dummies type dataframe from a column with a multiple of strings
body: <p>I have a column, 'col2', that has a list of strings. The current code I have is too slow, there's about 2000 unique strings (the letters in the example below), and 4000 rows. Ending up as 2000 columns and 4000 rows.</p>
  
  <pre><code>In [268]: df.head()
  Out[268]:
      col1    col2
  0   6       A,B
  1   15      C,G,A
  2   25      B
  </code></pre>
  
  <p>Is there a fast way to make this in a get dummies format? Where each string has it's own column and in each string's column there is a 0 or 1 if it that row has that string in col2.</p>
  
  <pre><code>In [268]: def get_list(df):
  d = []
  for row in df.col2:
      row_list = row.split(',')
      for string in row_list:
          if string not in d:
              d.append(string)
  return d
  
  df_list = get_list(df)
  
  def make_cols(df, lst):
      for string in lst:
          df[string] = 0
      return df
  
  df = make_cols(df, df_list)
  
  
  for idx in range(0, len(df['col2'])):
      row_list = df['col2'].iloc[idx].split(',')
      for string in row_list:
          df[string].iloc[idx]+= 1
  
  Out[113]:
  col1    col2    A   B   C   G
  0   6   A,B     1   1   0   0
  1   15  C,G,A   1   0   1   1
  2   25  B       0   1   0   0
  </code></pre>
  
  <p>This is my current code for it but it's too slow.</p>
  
  <p>Thanks you any help!</p>