title: Converting list in panda dataframe into columns
body: <pre><code>city        state   neighborhoods       categories
  Dravosburg  PA      [asas,dfd]          ['Nightlife']
  Dravosburg  PA      [adad]              ['Auto_Repair','Automotive']
  </code></pre>
  
  <p>I have above dataframe I want to convert each element of a list into column for eg:</p>
  
  <pre><code>city        state asas dfd adad Nightlife Auto_Repair Automotive 
  Dravosburg  PA    1     1   0   1         1           0    
  </code></pre>
  
  <p>I am using following code to do this :</p>
  
  <pre><code>def list2columns(df):
  """
  to convert list in the columns 
  of a dataframe
  """
  columns=['categories','neighborhoods']
  for col in columns:    
      for i in range(len(df)):
          for element in eval(df.loc[i,"categories"]):
              if len(element)!=0:
                  if element not in df.columns:
                      df.loc[:,element]=0
                  else:
                      df.loc[i,element]=1
  </code></pre>
  
  <ol>
  <li>How to do this in more efficient way?</li>
  <li><p>Why still there is below warning when I am using df.loc already</p>
  
  <pre><code>SettingWithCopyWarning: A value is trying to be set on a copy of a slice
  from a DataFrame.Try using .loc[row_indexer,col_indexer] = value instead
  </code></pre></li>
  </ol>