title: How to extract dataframe by row values by conditions with other columns?
body: <p>I have a dataframe as follows:</p>
  <pre><code>#values
  a=[&quot;003C&quot;, &quot;003P1&quot;, &quot;003P1&quot;, &quot;003P1&quot;, &quot;004C&quot;, &quot;004P1&quot;, &quot;004P2&quot;, &quot;003C&quot;, &quot;003P2&quot;, &quot;003P1&quot;, &quot;003C&quot;, &quot;003P1&quot;, &quot;003P2&quot;, &quot;003C&quot;, &quot;003P1&quot;, &quot;004C&quot;, &quot;004P2&quot;, &quot;001C&quot;, &quot;001P1&quot;]
  b=[&quot;chr18&quot;, &quot;chr20&quot;, &quot;chr8&quot;, &quot;chr8&quot;, &quot;chr11&quot;, &quot;chr11&quot;, &quot;chr11&quot;, &quot;chr11&quot;, &quot;chr11&quot;, &quot;chr11&quot;, &quot;chr1&quot;, &quot;chr1&quot;, &quot;chr1&quot;, &quot;chr1&quot;, &quot;chr1&quot;, &quot;chr11&quot;, &quot;chr11&quot;, &quot;chr9&quot;, &quot;chr9&quot;]
  c=[48399,145653,244695,244695,1163940,1163940,1163940,5986513,5986513,5986513,248650751,248650751,248650751,125895,125895,2587895,2587895,14587952,14587952]
  d=[&quot;C&quot;, &quot;G&quot;, &quot;C&quot;, &quot;C&quot;, &quot;C&quot;, &quot;C&quot;, &quot;C&quot;, &quot;G&quot;, &quot;G&quot;, &quot;G&quot;, &quot;T&quot;, &quot;T&quot;, &quot;T&quot;, &quot;T&quot;, &quot;T&quot;, &quot;C&quot;, &quot;C&quot;, &quot;T&quot;, &quot;T&quot;]
  e=[&quot;A&quot;, &quot;T&quot;, &quot;A&quot;, &quot;A&quot;, &quot;G&quot;, &quot;G&quot;, &quot;G&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;G&quot;, &quot;G&quot;, &quot;C&quot;, &quot;C&quot;]
  #Make dataframe
  df = pd.DataFrame({'Sample':a, 'CHROM':b, 'POS':c, 'REF':d, 'ALT':e})
  </code></pre>
  <p>df</p>
  <pre><code>    Sample  CHROM   POS         REF  ALT
  0   003C    chr18   48399       C    A
  1   003P1   chr20   145653      G    T
  2   003P1   chr8    244695      C    A
  3   003P1   chr8    244695      C    A
  4   004C    chr11   1163940     C    G
  5   004P1   chr11   1163940     C    G
  6   004P2   chr11   1163940     C    G
  7   003C    chr11   5986513     G    A
  8   003P2   chr11   5986513     G    A
  9   003P1   chr11   5986513     G    A
  10  003C    chr1    248650751   T    A
  11  003P1   chr1    248650751   T    A
  12  003P2   chr1    248650751   T    A
  13  003C    chr1    125895      T    A
  14  003P1   chr1    125895      T    A
  15  004C    chr11   2587895     C    G
  16  004P2   chr11   2587895     C    G
  17  001C    chr9    14587952    T   C
  18  001P1   chr9    14587952    T   C
  </code></pre>
  <p>I wanted to extract dataframe that matches <code>'CHROM' 'POS' 'REF' 'ALT'</code> for <code>df['Sample']</code> with <code>C</code> common with <code>P1</code> or <code>P2</code> or <code>P1</code> &amp; <code>P2</code>.
  For example <code>003C</code> : has its corrsponding 003P1 or 003P2 with with all matching values <code>'CHROM' 'POS' 'REF' 'ALT'</code> see index <code>7,8,9</code> and <code>13,14</code> and <code>10,11,12</code>. I wanted to extract them all:</p>
  <p>The expected output is:</p>
  <pre><code>    Sample  CHROM   POS       REF   ALT
  0   003C    chr1    125895     T    A
  1   003P1   chr1    125895     T    A
  2   004C    chr11   1163940    C    G
  3   004P1   chr11   1163940    C    G
  4   004P2   chr11   1163940    C    G
  5   004C    chr11   2587895    C    G
  6   004P2   chr11   2587895    C    G
  7   003C    chr11   5986513    G    A
  8   003P2   chr11   5986513    G    A
  9   003P1   chr11   5986513    G    A
  10  001C    chr9    14587952   T    C
  11  001P1   chr9    14587952   T    C
  12  003C    chr1    248650751  T    A
  13  003P1   chr1    248650751  T    A
  14  003P2   chr1    248650751  T    A
  </code></pre>
  <p>I tried following code:</p>
  <pre><code>df[['INT','STR']] = df['Sample'].str.extract('(\d+)(.*)')
  df = df[df.groupby(['CHROM', 'POS', 'REF', 'ALT', 'INT'])['STR'].transform('size').eq(3)]
  </code></pre>
  <p>But it pulls only common in all the three like <code>C, P1 and P2</code> not <code>C, P1 or P2</code>.</p>
  <p>Anyhelp appreciated. Thanks</p>