-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplayer_avg_rating.py
63 lines (45 loc) · 1.67 KB
/
player_avg_rating.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 30 12:31:00 2017
@author: Mohanakrishna
"""
from __future__ import division
import pandas as pd
dataset = pd.read_csv("updated_match.csv")
dir = "..\\datasets"
txtDir = "txt"
teamName = ""
teams = []
teamSignificance = ""
opponentTeamSignificance = ""
teamsStat = []
def getTeamsNamesList():
team_list = set(dataset.home_team)
list2 = (set(dataset.away_team))
team_list |= list2
teams.extend(team_list)
def getInfo(teams, matchesNumber):
for team in teams:
parseCSV(team)
saveResults(teamsStat, team)
del teamsStat[:]
def parseCSV(teamName):
for index, row in dataset.iterrows():
try:
isTeamHome = row['home_team'] == teamName
isTeamAway = row['away_team']== teamName
if isTeamHome:
teamsStat.append([row['home_team'], row['away_team'],row['home_player_avg'], row['away_player_avg'],row['past_perf_home'], row['past_perf_away'],row['home_team_goal'],row['away_team_goal'],20])
if isTeamAway:
teamsStat.append([row['away_team'],row['home_team'], row['away_player_avg'],row['home_player_avg'], row['past_perf_away'],row['past_perf_home'],row['away_team_goal'],row['home_team_goal'],10])
except:
pass
def saveResults(teamsStat, teamName):
resFile = open(txtDir + "/sortedData" + teamName+ ".txt", 'w')
for stat in teamsStat:
resFile.write( ("; ".join( repr(e) for e in stat ))+"\n" )
# resFile.write(''.join(str(stat)) + '\n')
resFile.close()
if __name__ == '__main__':
getTeamsNamesList()
getInfo(teams, len(teams))