1

我尝试对原始数据中的所需行实施简单的逻辑。我最终得到一个空的 csv 文件。我不知道我的代码有什么问题。

示例数据集在这里:

示例代码在这里:

with open ('tracksample.csv','r') as inp, open('final.csv','w') as out:
    writer = csv.writer(out)
    for row in csv.reader(inp):
        if (row[3] == "0" and row[4] == "0"):
            writer.writerows(row) 

任何线索将不胜感激并提前感谢。

4

1 回答 1

1
import csv
p=open('final.csv','w')
writer = csv.writer(p)
f=open('sample.csv','r')
for row in csv.reader(f):
    if row==[]:
        continue
    print(row)
    if (row[3] == "0" and row[4] =="0"):
            print(row)
            writer.writerow(row) 
    

p.close()
f.close()
于 2020-12-02T02:49:46.877 回答