我正在尝试遍历两个csv文件,并希望比较下一列值和前一列之间的字符串。程序正在使用一个csv文件,但有两个csv文件,它给出错误:File" Gaze_calculaton.py",88行in 如果行[3] =="凝视机器人": IndexError:列表索引超出范围
在第一个文件的末尾给出错误。我尝试了一些东西,但它没有用。请帮助,因为我是csvloop处理的新手。
import csv
import os,sys
import glob
dirListing = glob.glob('/home/shruti/Desktop/Final eaf files/Teacher Gaze/*.csv')
print dirListing
for fname in dirListing:
`enter code here`last =None
last1 =None
with open(fname,'rb') as f:
for row in list(csv.reader(f, delimiter=',')):
#print row[3]
i += 1
print i
print fname
if last == "Gaze at robot" and row[3]== "Gaze at learner" :
b += 1
print "b",b
print last
print row[3]
if last1 == "Gaze at learner" and row[3]== "Gaze at robot" :
c += 1
print "c",c
print last1
print row[3]
if row[3] == "Gaze at robot":
last = row[3]
if row[3] == "Gaze at learner":
last1 = row[3]
print b,c
f.close()