从csv中删除重复文本

时间:2013-10-11 08:27:25

标签: python csv

以下代码允许我实现此结果,但

  1. 我希望文件名和Type类似于旁边的图片,只包含一个。
  2. 有什么方法可以解决这个问题吗?
  3. enter image description here enter image description here

    if __name__ == '__main__': #start of program
    
    master = Tk()
    newDirRH = "C:/VSMPlots"
    FileName = "J12312312" 
    TypeName = "1234"
    Field = [1,2,3,4,5,6,7,8,9,10]
    Court = [5,4,1,2,3,4,5,1,2,3]
    
    
    newfile = newDirRH + "/Try1.csv"
    with open(newfile, "wb") as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(["FileName", "TypeName", "field", "court"])
        for field, court in zip(Field, Court):
            writer.writerow([FileName, TypeName, field, court])
    print "Done"
    

1 个答案:

答案 0 :(得分:2)

在第一次循环迭代后将FileNameTypeName设置为空字符串。

...
for field, court in zip(Field, Court):
    writer.writerow([FileName, TypeName, field, court])
    FileName = TypeName = '' # <---
...