title: Pandas group by either column
body: <p>I want to find the groups (rather than the grouping variable) in a pandas groupby. Here is an example:</p>
  <pre><code>Name    Col1    Col2    Col3
  John    1       A       C
  Sam     1       B       C
  Mike    1       B       D
  Kate    2       E       G
  Fred    3       E       H
  Liz     3       F       H
  Jane    4       X       Y
  Henry   4       Z       T
  </code></pre>
  <p>If I group then using <code>Col1 and (Col2 or Col3)</code>, the corresponding groups  will be</p>
  <pre><code>output = [['John', 'Sam', 'Mike'], ['Kate'], ['Fred', 'Liz'], ['Jane'], ['Henry']]
  </code></pre>
  <p>because a group consists of people having the same <code>Col1</code> values, as well as either the same Col2 or the same Col3 value.</p>
  <p>I was able to get what I want by creating a graph and finding connected components. Grouping by <code>Col1</code> first, then finding connected components is another idea. However, I believe there must be a simpler way.</p>
  <p>I would also like to do this in a more general case, such as grouping by <code>Col1 and Col2 and (Col3 or Col4) and (Col5 or Col6)</code>.</p>