I want to loop through a csv document and often check the next row for values, but stick to the same row number. The .next() is skipping a row, which won't work for me, unless I could go back again somehow. Is there a simple way in doing this? I tried the pairwise/cycle but it takes way too long if the file is big. My sample code is:
file1 = open("name.csv", 'rb')
reader = csv.DictReader(file1)
new_rows_list = []
for row in reader:
if row['IsFixated'] == 'TRUE':
new_row = [row['Result'], 'Fixation']
new_rows_list.append(new_row)
else:
new_row = [row['Result'], 'Saccade']
new_rows_list.append(new_row)
nextRow = reader.next() # check for next row ??
if nextRow['IsFixated'] == 'TRUE':
new_rows_list = CheckPreviousPositions(new_rows_list)
file1.close()