title: How to merge whole rows with specific statement in pandas?
body: <p>I have a logic problem, and I can't figure it out without using for loop (it's large DF, and for its too slow).</p>
  <p>DF:</p>
  <pre><code>Gene1    person1  TA   path1
  Gene1    person1  TA   path2
  Gene2    person1  CG   path1
  Gene1    person2  GG   path3
  Gene2    person2  CG   path1
  Gene2    person2  CA   path3
  Gene2    person2  CG   path4
  Gene1    person3  GG   path6
  Gene3    person3  GA   path2
  Gene3    person3  GC   path12
  ...
  </code></pre>
  <p>And in above I have three cases:</p>
  <ol>
  <li>person1 has 2x gene1 with allele TA - it shoud be merged (path it's whatewer but one need to be)</li>
  <li>person2 has 3x gene2 with CG/CA/CG - it should be flattened to the most common so CG with path1 or 4</li>
  <li>person3 has 2x gene3 with GA/GC  so both that rows shoud be just delete, coz it's not possible to get most common.</li>
  </ol>
  <p>Rest shoud be without change.</p>
  <p>So result shoud looks like that:</p>
  <pre><code>    Gene1    person1  TA   path1 or path2
      Gene2    person1  CG   path1
      Gene1    person2  GG   path3
      Gene2    person2  CG   path4 or 1
      Gene1    person3  GG   path6
      ...
  </code></pre>
  <p>And what else? that file is large, has 100k persons and 3 Genes, one person can have X numbers on same genes with different path (it's collect from 1k different files).</p>
  <p>What I tried?
  Just loop whole dataframe wiht tree different for. One for count, one for deleting duplicated and merge and last for validation.
  But I know it's naive and bad solution (it takes 20+ min), so I will be grateful for any advice how to figure out that problem.</p>