You open the file more than once for which row with score greater than 3.
Every time you open a file for writing it truncates an existing one with the same name.

On 13/03/17 13:25, Madhusudhanan Sambath wrote:
hi to all,
this is madhu...i am new to python

this is my python code, where i labeled the reviews taken from amazon as 
positive, negative and neutral based on review score

i have collected reviews and scores from amazon scrap prg, but i have problem 
while doing labelling.kindly help me

import nltk
import csv
import ast

data=[]
positivedata=[]
negativedata=[]
neutraldata=[]




with open('E:/amadown2py-master/reviews1.csv', 'r',encoding='UTF8') as csvfile:
     mycsv = csv.reader(csvfile)
     for row in mycsv:
         data = row[0]
         #print (data)
         try:
             score = ast.literal_eval(row[1])
             if score > 3:
                 cnt=0;
                 #print (score)
                 print (data)
                 positivedata.append((data))
                 with open('E:/amadown2py-master/Sam7_pos_rev.txt',mode='wt') 
as myfile:
                     myfile.writelines('\n'.join(positivedata))
                     myfile.close()


the above program is able to create file but full reviews are not read from csv 
. if i print the details about 48kb size, i got more data , but in file it have 
only 3kb why?kinldy help me




--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to