-2
这里是输入CSV该代码会被读取队名蟒蛇遍历列表中的时间范围,并制定出平均
team_name half_goals FT_goals shots shots_on_target corners Result
Arsenal 1 1 16 4 4 L
Liverpool 1 1 26 11 12 W
Norwich 0 2 8 2 6 D
Sunderland 0 0 20 3 6 L
Swansea 0 1 17 6 7 L
West Brom 0 0 11 1 4 L
West Ham 1 2 18 4 4 W
Chelsea 2 2 22 5 5 W
Crystal Palace 0 0 5 3 3 L
Man City 2 4 20 11 8 W
Chelsea 1 2 15 3 1 W
Aston Villa 0 0 17 3 8 L
Everton 0 0 22 8 11 D
Fulham 0 1 16 7 1 L
这里是想阅读次数团队其中L码被提及然后算出平均值
import csv
from datetime import datetime
with open('League.csv','r') as csvfile:
readCSV = csv.reader(csvfile,delimiter=',')
next(readCSV)
for row in readCSV:
#print(row)
lines = []
lines.append(row)
#print (lines)
teams = set()
#print (teams)
for line in lines :
home_team = line[2]
teams.add(home_team)
#print (teams)
for team in teams:
match = [line for line in lines if line[2]==team]
#print(match)
for i in range(5, len(match)):
history = match [i-5:i]
average = (history/5)
print(average)
我想要做的是带来一个平均每5次比赛中提到哪支球队。
期望输出
game 1-5 Team one --- average
game 2-6 Team one --- average
game 3-7 Team one --- average
谢谢。
请首先指定输入/预期输出... –
谢谢,我已经这样做了... –