title: Creating a dataframe with binary valued columns with pandas using values from an existing dataframe
body: <p>I am trying to create a new dataframe with binary (0 or 1) values from an exisitng dataframe. For every row in the given dataframe, the program should take value from each cell and set 1 for the corresponding columns of the row indexed with same number in the new dataframe</p>
  
  <p><a href="https://i.stack.imgur.com/AWvYI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AWvYI.png" alt="Structure of the existing dataframe"></a></p>
  
  <p><a href="https://i.stack.imgur.com/SaYwD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SaYwD.png" alt="Structure of the new dataframe"></a></p>
  
  <p>I have tried executing the following code snippet.</p>
  
  <pre><code>for col in products :
      index = 0;
      for item in products.loc[col] :
          products_coded.ix[index, 'prod_' + str(item)] = 1;
          index = index + 1;
  </code></pre>
  
  <p>It works for less number of rows. But,it takes lot of time for any large dataset. What could be the best way to get the desired outcome.</p>