我尝试在csv文件中填充新列(' light_during_5hours_ago'),具体取决于时间列,但在5小时之前,如果光柱中的记录为1,则将1放入其他位置0,我得到这个错误?
文件"",第11行 对于csvfile.seek(testdata.Time< = t): ^ SyntaxError:语法无效
这是我的代码和文件的一部分
with open('G:/testdata.csv', 'r') as csvfile:
with open('G:/testdata1.csv', 'w') as csvoutput:
row.append('light_during_5hours_ago')
for row in csvfile:
row_identify = row[0]
row_identify1 = row[1]
for row in csvfile:
for row_identify in row:
for csvfile.seek(testdata.Time<=t):
if row_identify1 =='1':
row.append(1)
else:
row.append(0)
all.append(row)
writer.writerows(all)
数据:
Time light lock ismart
3/26/2018 6:16 1 0 0
3/26/2018 6:17 1 0 0
3/26/2018 7:40 1 0 0
3/26/2018 7:40 1 0 0
3/26/2018 7:40 1 0 0
3/26/2018 7:40 1 0 0
3/26/2018 7:40 1 0 0
3/26/2018 7:40 1 0 0
3/26/2018 7:40 1 0 0
3/26/2018 7:40 1 0 0
3/26/2018 7:41 1 0 0
3/26/2018 8:52 1 0 0
答案 0 :(得分:0)
csvfile.seek(testdata.Time<=t)
不是迭代器;你不能用它作为for
循环的控制。请注意表达式与前一个语句的区别。我怀疑你遗漏了一个变量,比如
for dummy in csvfile.seek(testdata.Time<=t):