Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- COLUMN 0
- some@email.com
- some@email.com
- another@address.com
- example@email.com
- COLUMN 0 COLUMN 1
- some@email.com 2
- another@address.com 1
- example@email.com 1
- 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] )
- from collections import defaultdict
- # count all the emails before we write anything out
- emails = defaultdict(int)
- for row in f:
- emails[row[0]] += 1
- # now write the file
- for row in email.items():
- writer.writerow(row)
- from collections import Counter
- emails=Counter()
- for row in f:
- emails+=Counter([row[0]])
- Counter({'some@email.com': 2, 'another@address.com': 1, 'example@email.com': 1, 'COLUMN 0': 1})
- print set(emails.elements())
- # set(['another@address.com', 'COLUMN 0', 'example@email.com', 'some@email.com'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement