I have a CSV file rsvp1.csv
:
_id event_id comments
1 | x | hello..
2 | y | bye
3 | y | hey
4 | z | hi
My question is:
For each event e how can I get the comments written to a separate text file?
There is some error with the following code:
import csv
with open('rsvps1.csv','rU') as f:
reader = csv.DictReader(f, delimiter=',')
rows = list(reader)
fi = open('rsvp.txt','wb')
k=0
for row in rows:
if k == row['event_id']:
fi.write(row['comment']+"\n")
else:
fi.write(row['event_id']+"\t")
fi.write(row['comment']+"\n")
k= row['event_id']
f.close()
fi.close()