def positive_and_negative_to_full():
fpos = open('positive.csv')
positive_units = [row for row in csv.reader(fpos)]
fneg = open('negative.csv')
negative_units = [row for row in csv.reader(fneg)]
for item in positive_units:
item.append('positive')
for item in negative_units:
item.append('negative')
del negative_units[0]
positive_units[0][0] = 'review_content'
positive_units[0][1] = 'sentiment'
full = positive_units
full.extend(negative_units)
with open('positiveandnegative.csv', 'wb') as csvfile:
writer = csv.writer(csvfile, dialect='excel')
writer.writerows(full)
#this will open the review scraped data and write two files from that info:
#positive.csv, containing positive opinion units
#negative.csv, containing negative opinion units
评论列表
文章目录