title: Selecting rows from a Dataframe based on values in multiple columns in pandas
body: <p>This question is <em>very</em> related to <a href="https://stackoverflow.com/questions/17071871/select-rows-from-a-dataframe-based-on-values-in-a-column-in-pandas">another</a>, and I'll even use the example from the very helpful accepted solution on that question. Here's the example from the accepted solution (credit to unutbu):</p>
  
  <pre><code>import pandas as pd
  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})
  print(df)
  #      A      B  C   D
  # 0  foo    one  0   0
  # 1  bar    one  1   2
  # 2  foo    two  2   4
  # 3  bar  three  3   6
  # 4  foo    two  4   8
  # 5  bar    two  5  10
  # 6  foo    one  6  12
  # 7  foo  three  7  14
  
  print(df.loc[df['A'] == 'foo'])
  </code></pre>
  
  <p>yields</p>
  
  <pre><code>     A      B  C   D
  0  foo    one  0   0
  2  foo    two  2   4
  4  foo    two  4   8
  6  foo    one  6  12
  7  foo  three  7  14
  </code></pre>
  
  <p>But what if I want to pick out all rows that include both 'foo' and 'one'? Here that would be row 0 and 6. My attempt at it is to try</p>
  
  <pre><code>print(df.loc[df['A'] == 'foo' and df['B'] == 'one'])
  </code></pre>
  
  <p>This does not work, unfortunately. Can anybody suggest a way to implement something like this? Ideally it would be general enough that there could be a more complex set  of conditions in there involving <code>and</code> and <code>or</code>, though I don't actually need that for my purposes.</p>