I have a CSV file with some data, I need to write to the a new CSV but I can't have duplicate entries.
I have solved the writing part but I have not been able to solve the duplicate part. I have so far tried a nested loop but with 0 success.
This works but has duplicates
with open('somefile.csv', 'w') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
filewriter.writerow(['Data', 'MoreData', 'EvenMoreData'])
for row in rows:
# parsing each column of a row
filewriter.writerow([row[3], row[4], row[2]])
Where everything goes wrong
for row in rows:
# parsing each column of a row
for copy in rows:
if row[3] != copy[3] and row[2] != copy[2]:
filewriter.writerow([copy[3], copy[4], copy[2]])