title: Python - Display rows with repeated values in csv files
body: <p>I have a .csv file with several columns, one of them filled with random numbers and I want to find duplicated values there. In case there are - strange case, but it's what I want to check after all -, I would like to display/store the complete row in which those values are stored.</p>
  
  <p>To make it clear, I have sth like this:</p>
  
  <blockquote>
    <p>First, Whatever, 230, Whichever, etc<br>
     Second, Whatever, 11, Whichever, etc<br>
     Third, Whatever, 46, Whichever, etc<br>
     Fourth, Whatever, 18, Whichever, etc<br>
     Fifth, Whatever, 14, Whichever, etc<br>
     Sixth, Whatever, 48, Whichever, etc<br>
     Seventh, Whatever, 91, Whichever, etc<br>
     Eighth, Whatever, 18, Whichever, etc<br>
     Ninth, Whatever, 67, Whichever, etc</p>
  </blockquote>
  
  <p>And I would like to have:</p>
  
  <blockquote>
    <p>Fourth, Whatever, 18, Whichever, etc<br>
     Eighth, Whatever, 18, Whichever, etc</p>
  </blockquote>
  
  <p>To find duplicated values, I store that column into a dictionary and I count every key in order to discover how many times they appear.  </p>
  
  <pre><code>import csv
  from collections import Counter, defaultdict, OrderedDict
  
  with open(file, 'rt') as inputfile:
          data = csv.reader(inputfile)
  
          seen = defaultdict(set)
          counts = Counter(row[col_2] for row in data)
  
  print "Numbers and times they appear: %s" % counts
  </code></pre>
  
  <p>And I see</p>
  
  <blockquote>
    <p>Counter({' 18 ': 2, ' 46 ': 1, ' 67 ': 1, ' 48 ': 1,...}) </p>
  </blockquote>
  
  <p>The problem comes now because I don't manage to link the key with the repetitions and compute it later. If I do</p>
  
  <pre><code>for value in counts:
          if counts &gt; 1:
              print counts
  </code></pre>
  
  <p>I would be taking only the key, which is not what I want and every value (not to mention that I'm looking to print not only that but the whole line...)</p>
  
  <p>Basically I'm looking for a way of doing</p>
  
  <pre><code>If there's a repeated number:
          print rows containing those number
  else
          print "No repetitions"
  </code></pre>
  
  <p>Thanks in advance.</p>