python - why loop did not execute else -
import csv path1=r'/users/desktop/forks.csv' path2=r'/users/desktop/forks1.csv' outdata=[] count=0 i=0 open(path1,'rb') input: reader=csv.reader(input) row in reader: if i==0: i=i+1 outdata.append(row) continue if int(row[5])>0: row.append(1) outdata.append(row) count=count+1 print count else: row.append(0) outdata.append(row) count=count+1 print count open (path2,'wb') output: writer=csv.writer(output,delimiter=',') writer.writerows(outdata)
i have large table, want add column boolean value each row. if column 6 lager 0, should 1. if 0, should zero. loop stop @
58542 58543 58544 58545 58546 58547 58548 traceback (most recent call last): file "/users/documents/workspace/datamining/opensource/label.py", line 18, in <module> if int(row[5])>0: valueerror: invalid literal int() base 10: ''
the information in table below, means else loop did not execute. test in small table,the code works.i don't know why cannot work in large dataset?
58547 1 58548 1 58549 0 58550 0
valueerror: invalid literal int() base 10: ''
you're passing empty value argument int
. int
cannot convert empty value integer.