如何将python代码中的for循环写入csv文件?

2024-09-28 23:08:26 发布

您现在位置:Python中文网/ 问答频道 /正文

在这段代码中,我试图读取csv文件并找到总通过和失败数,并且必须将第二个for循环段插入csv文件中

    d=dfs[i]['Filename'].tolist()
    total=len(dfs[i].IngestionStatus)
    tpass=len(dfs[i][dfs[i]['IngestionStatus'] == 'Pass']) 
    tfail=total-tpass
    print ("SNo\t\tName\t\tTotal\t\tTotalPass\t\tTotalFail")
    print ("------------------------------------------------------------------------------------")
    for j in range(1):
        print ("%d:\t\t%s\t\t%d\t\t%d\t\t\t%d" % (j,d[j] ,total,tpass,tfail))
    print ("------------------------------------------------------------------------------------")```

Need to convert this section of the code into a table and insert it into a csv file 

Tags: 文件csv代码forlenpassfilenametotal