title: data frames with a for loop
body: <p>I am relatively new to Python and came across an interesting piece of code that I am trying to understand in greater detail. My data frame looks something like this:</p>
  
  <pre><code>import pandas as pd
  d = {'business': ['FX','a','CR'], 'A/L': ['A','A','L']}
  data = pd.DataFrame(data=d)
  data
  </code></pre>
  
  <p>Someone very kindly posted the following piece of code on this site:</p>
  
  <pre><code>cols=data.columns
  pd.DataFrame({col: data[col].str.contains('#') for col in cols})
  </code></pre>
  
  <p>I understand what the code inside the pd.DataFrame is doing. However, I cannot find any documentation on how the for loop works in the above context. This does not look like a list comprehension even though it works something like a list comprehension. </p>
  
  <p>Can someone point me to some documentation / tutorial that explains how to use the syntax above ?</p>