title: Python Pandas GroupBy equivalent of If A and not B where clause in SQL
body: <p>I am using <code>pandas</code> <code>groupby</code> and was wondering how to implement the following:</p>
  
  <ol>
  <li><p>Dataframes A and B have the same variable to index on, but A has 20 unique index values and B has 5. </p></li>
  <li><p>I want to create a dataframe C that contains rows whose indices are present in A and not in B. </p></li>
  <li><p>Assume that the 5 unique index values in B are all present in A. C in this case would have only those rows associated with  index values in A and not in B (i.e. 15).</p></li>
  <li><p>Using inner, outer, left  and right do not do this (unless I misread something).</p></li>
  </ol>
  
  <p>In SQL I might do this as <code>where A.index &lt;&gt; (not equal) B.index</code></p>
  
  <p><strong>My Left handed solution:</strong></p>
  
  <p>a) get the respective index columns from each data set, say x and y.</p>
  
  <p>def match(x,y,compareCol):</p>
  
  <pre><code>"""
  
  x and y are series
  
  compare col is the name to the series being returned .
  
  It is the same name as the name of x and y in their respective dataframes"""
  
  x = x.unique()
  
  y = y.unique()
  
  """ Need to compare arrays x.unique() returns arrays"""
  
  new = []
  
  for item in (x):
  
      if item not in y:
  
          new.append(item)
  
  returnADataFrame = pa.DataFrame(pa.Series(new, name = compareCol))
  
  return returnADataFrame
  </code></pre>
  
  <p>b) now do a left join on this on the data set A.</p>
  
  <p>I am reasonably confident that my elementwise comparison is slow as a tortoise on weed with no 
  motivation.</p>