# -*- coding:utf-8 -*-
import csv
def readbyday(csvfile,day):
csvcontent = csv.reader(file(csvfile, 'rb'))
res=[]
for line in csvcontent:
if line[0].find(day)<>-1:
res.append(line)
return res
def calcbyday(csvfile,day,flag):
#æ±æåæ°æ®çååå¹³åå¼
total=0
avg=0
res=readbyday(csvfile, day)
for i in res:
print i
total=total+int(i[flag])
avg=total/len(res)
return total,avg
date='2014-7-1'
flag=1 #falg=1/2/3 æ¶å
¥éé¢/æ¯åºéé¢/ä½é¢éé¢
total,avg=calcbyday(u'7æ_1.csv',date,1)
print '%s æ¶å
¥éé¢æ»æ°:%d\tå¹³å:%d'%(date,total,avg)
è¾åºï¼
['2014-7-1 0:01', '100', '80', '10000']
['2014-7-1 0:01', '101', '81', '10001']
['2014-7-1 0:08', '102', '82', '10002']
2014-7-1 æ¶å
¥éé¢æ»æ°:303 å¹³å:101
温馨提示:答案为网友推荐,仅供参考