So I have a csv file I want to import and want to skip importing both the duplicate and the original line from the csv file based on a user number in the first column and I'm using the StringIO module. The way I'm doing it currently is below which is incorrect because even though it skips the duplicate line, it'll still import the original line I believe. What would be the best way to skip importing both duplicate and original lines from csv?
def csv_import(stream):
ostream = StringIO()
headers = stream.readline()
ostream.write(headers)
seen_user_numbers = {}
for row in stream:
list_row = row.split(',')
user_number = list_row[0]
if user_number in seen_user_numbers:
seen_user_numbers.pop(user_number)
continue
seen_user_numbers[user_number] = True
ostream.write(row)
ostream.seek(0)
return ostream