I imagine this is an easy one for a decent Python dev – Im still learning! Given a csv with duplicate emails I would like to iterate and write out the count of duplicate emails eg:
infile.csv
COLUMN 0
some@email.com
some@email.com
another@address.com
example@email.com
outfile.csv
COLUMN 0 COLUMN 1
some@email.com 2
another@address.com 1
example@email.com 1
So far I can remove duplicates with
import csv
f = csv.reader(open('infile.csv','rb'))
writer = csv.writer(open('outfile.csv','wb'))
emails = set()
for row in f:
if row[0] not in emails:
writer.writerow(row)
emails.add( row[0] )
but I am having trouble writing the count to a new column.
Using
defaultdictwhich is in Python2.6