title: Pandas: If item in list equals column value, append
body: <p>I have a question about some code using <code>python3</code>/<code>pandas</code>.</p>
  
  <p>I have a list</p>
  
  <pre><code>mylist = [2,6,7]
  </code></pre>
  
  <p>and a dataframe</p>
  
  <pre><code>import numpy as np
  df = pd.DataFrame({'A': 'foo bar foo bar foo bar foo foo'.split(),
                     'B': 'one one two three two two one three'.split(),
                     'C': np.arange(8), 'D': np.arange(8) * 2})
  </code></pre>
  
  <p>Now I want to check, if an item of <code>mylist</code> equals a value of column <code>C</code> in <code>df</code>. If it does, make a new <code>df2</code> with the rows that gave a match.</p>
  
  <pre><code>col = ["A", "B", "C", "D"]
  df2 = pd.DataFrame(columns=col)
  for x in mylist:
      if len(df.loc[df['C'] == x])&gt;=1:
          df2.append(df.loc[df['C'] == x])
  </code></pre>
  
  <p>Unfortunately, that does not work (I don't get any output).
  My expected output (<code>df2</code>) would be:</p>
  
  <pre><code>index   A   B       C   D
  2       foo two     2   4
  6       foo one     6   12
  7       foo three   7   14
  </code></pre>