title: Faster way to filter and counting rows in pandas
body: <p>I have a table with 300k rows. It contains data with genes for samples of animals. I have 43k animals, each has a 190-202 genes (they could be different e.g. one animal could have an AA1 gene, second could have not that one). 
  Example data frame looks that:</p>
  
  <pre><code>Gene_Name   AnimalNumber   Allele1   Allele2
  AA1          0001            B          B
  DSD          0001            A          B
  KAD334       0001            A          B
  EE2          0001            A          A
  AA1          0002            A          A
  DSD          0002            A          A
  EE2          0002            A          B
  COPA         0002            B          B
  </code></pre>
  
  <p>What I need to do?</p>
  
  <ol>
  <li>Need to count how many gene is appear in table. I just use <code>df[Gene_name].value_counts()</code> and it's ok.</li>
  <li>Need to count how many genes appear in specific Alleles configurations. For example configurations could be only: AA, AB, BB. </li>
  </ol>
  
  <p>And I think it's my weak point, coz I just put all SNP names to list, and create for loop like this:</p>
  
  <pre><code>  for i in range(len(genelist)):
      pick = len(df[df['Gene_Name']==genelist[i]].where(genotyp['Allele1'] == 'A' | genotyp['Allele2'] == A).dropna())
      listOfResults.append(pick)
  </code></pre>
  
  <p>And I run that loop three times. One for AA, one for BB, one for AB. It's works but it takes few hours :(
  So how to do it by pandas without obvius loop? I mean faster...</p>
  
  <pre><code>Expect result:
  Gene_Name     all      AA      AB      BB
  AA1           3330     2230   1000     0
  DSD           1000     870    100      30
  ...
  etc.
  </code></pre>
  
  <p>I got 'all' column as I said. How to speed up collecting data for 2nd, 3rd and 4th.</p>
  
  <p>I didn't find anything helpfull to my problem.</p>
  
  <p>I will be grateful for the help.</p>