title: Python Pandas: How to create a binary matrix from column of lists?
body: <p>I have a Python Pandas DataFrame like the following:</p>
  
  <pre><code>      1
  0  a, b
  1     c
  2     d
  3     e
  </code></pre>
  
  <p><code>a, b</code> is a string representing a list of user features</p>
  
  <p>How can I convert this into a binary matrix of the user features like the following:</p>
  
  <pre><code>     a    b    c    d    e
  0    1    1    0    0    0
  1    0    0    1    0    0
  2    0    0    0    1    0
  3    0    0    0    0    1
  </code></pre>
  
  <p>I saw a similar question <a href="https://stackoverflow.com/questions/32505207/creating-boolean-matrix-from-one-column-with-pandas">Creating boolean matrix from one column with pandas</a> but the column does not contain entries which are lists.</p>
  
  <p>I have tried these approaches, is there a way to merge the two:</p>
  
  <p><strong><code>pd.get_dummies()</code></strong></p>
  
  <pre><code>pd.get_dummies(df[1])
  
  
     a, b  c  d  e
  0     1  0  0  0
  1     0  1  0  0
  2     0  0  1  0
  3     0  0  0  1
  </code></pre>
  
  <p><strong><code>df[1].apply(lambda x: pd.Series(x.split()))</code></strong></p>
  
  <pre><code>      1
  0  a, b
  1     c
  2     d
  3     e
  </code></pre>
  
  <p>Also interested in different ways to create this type of binary matrix!</p>
  
  <p>Any help is appreciated!</p>
  
  <p>Thanks</p>