title: Sorting entire csv by frequency of occurence in one column
body: <p>I have a large CSV file, which is a log of caller data.</p>
  <p>A short snippet of my file:</p>
  <pre><code>CompanyName    High Priority     QualityIssue
  Customer1         Yes             User
  Customer1         Yes             User
  Customer2         No              User
  Customer3         No              Equipment
  Customer1         No              Neither
  Customer3         No              User
  Customer3         Yes             User
  Customer3         Yes             Equipment
  Customer4         No              User
  </code></pre>
  <p>I want to sort the entire list by the frequency of occurrence of customers so it will be like:</p>
  <pre><code>CompanyName    High Priority     QualityIssue
  Customer3         No               Equipment
  Customer3         No               User
  Customer3         Yes              User
  Customer3         Yes              Equipment
  Customer1         Yes              User
  Customer1         Yes              User
  Customer1         No               Neither
  Customer2         No               User
  Customer4         No               User
  </code></pre>
  <p>I've tried <code>groupby</code>, but that only prints out the Company Name and the frequency but not the other columns, I also tried</p>
  <pre><code>df['Totals']= [sum(df['CompanyName'] == df['CompanyName'][i]) for i in xrange(len(df))]
  </code></pre>
  <p>and</p>
  <pre><code>df = [sum(df['CompanyName'] == df['CompanyName'][i]) for i in xrange(len(df))]
  </code></pre>
  <p>But these give me errors:</p>
  <blockquote>
  <p>ValueError: The wrong number of items passed 1, indices imply 24</p>
  </blockquote>
  <p>I've looked at something like this:</p>
  <pre><code>for key, value in sorted(mydict.iteritems(), key=lambda (k,v): (v,k)):
      print &quot;%s: %s&quot; % (key, value)
  </code></pre>
  <p>but this only prints out two columns, and I want to sort my entire CSV. My output should be my entire CSV sorted by the first column.</p>
  <p>Thanks for the help in advance!</p>