I have a csv file and it contains 4 blank records (rows[0]) in csv file at row 147. and I have to ignore them and continue reading other rows in csv file.
For the blew logic it captures only records till the point it hits blank row and exits i.e row(146) and rest of the rows are ignored.
counter=0
with open('file_march15_l1.CSV','rU') as infile:
reader=csv.reader( (line.replace('\0','') for line in infile) )
for row in reader:
try:
if row[0]:
counter=counter+1
print('==='+row[1]+'===>')
result[row[0]].append(row[1])
except IndexError:
pass
pp.pprint(len(result))
print("Count rows:"+str(counter))
output of above snippet is:
146
Count rows:1049
==
So here I need to capture all records except 4 blank records.
I tired looking at below link and no luck as it capture till row 146 and rest of the rows are ignored(i.e after blank records). Python CSV error: line contains NULL byte
Appreciate any help to capture all records!