remove duplicate rows in csv file python

Solutions on MaxInterview for remove duplicate rows in csv file python by the best coders in the world

showing results for - "remove duplicate rows in csv file python"
Giovanni
26 Jul 2019
1# credit to the Stack Overflow user in the source link
2
3with open('file_with_duplicates.csv','r') as in_file, open('ouput.csv','w') as out_file:
4  
5    seen = set() # set for fast O(1) amortized lookup
6    
7    for line in in_file:
8        if line in seen: 
9          continue # skip duplicate
10
11        seen.add(line)
12        out_file.write(line)