使用 Python 计算 CSV 行中的总和
问题描述:
我想在保存为 .csv 的 Excel 文件中用 Python 计算每行的总和
I want to calculate sum of each row with Python in Excel file saved as .csv
像这个例子:
答
你可以试试这样的:
import csv
with open('foo.csv') as csvfile:
spamreader = csv.reader(csvfile)
for row in spamreader:
sum = 0
for i in row:
sum += int(i)
print(sum)