如何在python中写入csv文件

时间:2018-09-16 20:27:55

标签: python csv

我想将此输出写入csv文件,但不幸的是我不能

with open('file.csv') as fin:
    reader = csv.reader(fin)
    for row in reader:
        name = row[0]
        grades = []
        for grade in row[1:]:
            grades.append(int(grade))
        print('%s,%f'%(name, mean(grades)))

file.csv之类的

joe,13,20,19,18
jim,23,43,24,76
john,4,13,4,22

输出文件应如下所示:

Joe,17.50
jim,41.50
John,10.75

0 个答案:

没有答案