Reputation: 12568
I am looping through a CSV and creating a new one in 'python3' like this...
for row in csvreader:
with open('employee_file.csv', mode='w', encoding='utf-8') as employee_file:
employee_writer = csv.writer(employee_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
employee_writer.writerow([row[0],employeeName])
But once it finished processing I am left with only the last result in employee_file.csv. Where am I going wrong?
Upvotes: 0
Views: 407
Reputation: 1777
Take the file opening line before the for loop. The way you have it now you keep writing it over in the for loop.
with open('employee_file.csv', mode='w', encoding='utf-8') as employee_file:
for row in csvreader:
...
Upvotes: 1