I have a CSV file, which looks like this:
id,text,initial_score
1,"Today's news: Democrats offer Republicans everything they asked for; Republicans demand more. Not hard to understand: R's want a shutdown.",0
I want to create a new file, which include the same fields and add a new field as a column. The new field will be a result of an equalization.I used the following code but there is a syntax error:
f1 = open(filepathIntro)
f = open(filepath)
for line in f1:
cols = split_line(line)
words1 = get_tweet_words(cols)
total_score = 0
for w1 in words1:
for line in f:
if not line.startswith("#"):
cols = split_line(line)
words2 = get_words(cols)
for w2 in words2:
if w1 == w2:
posnum = float(get_positive(cols))
negnum = float(get_negative(cols))
total_score = total_score + (posnum - negnum)
with open(filepathIntro, 'r') as f1, open('semevalSenti.csv', 'w+' ) as fout:
reader = csv.reader(f1)
writer = csv.writer(fout)
writer.writerow(next(reader) + ['Total score'])
writer.writerows([reader] + float(total_score) )
The message error is:
writer.writerows([a] + total_score for a,total_score in zip(reader,total_score)) TypeError: zip argument #2 must support iteration
Could you please help me? Thanks in advance!!!!!!