Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2019
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. COLUMN 0
  2. some@email.com
  3. some@email.com
  4. another@address.com
  5. example@email.com
  6.  
  7. COLUMN 0 COLUMN 1
  8. some@email.com 2
  9. another@address.com 1
  10. example@email.com 1
  11.  
  12. import csv
  13.  
  14. f = csv.reader(open('infile.csv','rb'))
  15. writer = csv.writer(open('outfile.csv','wb'))
  16. emails = set()
  17.  
  18.  
  19. for row in f:
  20. if row[0] not in emails:
  21. writer.writerow(row)
  22. emails.add( row[0] )
  23.  
  24. from collections import defaultdict
  25.  
  26. # count all the emails before we write anything out
  27. emails = defaultdict(int)
  28. for row in f:
  29. emails[row[0]] += 1
  30.  
  31. # now write the file
  32. for row in email.items():
  33. writer.writerow(row)
  34.  
  35. from collections import Counter
  36.  
  37. emails=Counter()
  38. for row in f:
  39. emails+=Counter([row[0]])
  40.  
  41. Counter({'some@email.com': 2, 'another@address.com': 1, 'example@email.com': 1, 'COLUMN 0': 1})
  42.  
  43. print set(emails.elements())
  44. # set(['another@address.com', 'COLUMN 0', 'example@email.com', 'some@email.com'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement