title: Python version of an Excel Formula
body: <p>I'm currently creating a Python 3 program that will pick out the most frequent numbers from a six-column CSV. So far I have the code that will pick the most frequent from each column, but I also want code that can pick the six most frequent (from the 1st most frequent, to the 6th) number from all the columns and rows combined.</p>
  
  <p>I have an Excel spreadsheet that does it, using the formula:</p>
  
  <pre><code>=MODE(IF(1 - ISNUMBER(MATCH(B2:G402,$L$24:L24,0)),B2:G402))
  </code></pre>
  
  <p>Then dragging the calculation down to display six numbers (as far as I can tell this is a working formula!)</p>
  
  <p>Is there a way I can get that formula, or something better, in Python 3? So the code will display the top six most frequent numbers from six columns and 400+ rows?</p>
  
  <p>Here's my code so far:</p>
  
  <pre><code>import csv
  import os
  import random
  
  
  from collections import Counter
  filename='lotto.csv'
  
  os.system('cls' if os.name == 'nt' else 'clear')
  print("\n\n********** Lottery Number Generator **********\n\n")
  print("Based on all previous Lotto numbers from CSV.\n")
  
  x = 1
  while x &lt; 8:
  
      with open(filename, 'r') as f:
        column = (row[x] for row in csv.reader(f))
        print("Lotto Number", x, ": {0}".format(Counter(column).most_common()[0][0]))
        x = x + 1
  </code></pre>
  
  <p>Any ideas, guys?</p>
  
  <p>Thanks in advance!</p>
  
  <p>Dave     </p>