-
Notifications
You must be signed in to change notification settings - Fork 3
/
FetchUnderstatData.py
69 lines (58 loc) · 2.1 KB
/
FetchUnderstatData.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
64
65
66
67
68
69
import aiohttp
from understat import Understat
import pandas as pd
async def test():
async with aiohttp.ClientSession() as session:
understat = Understat(session)
player = await understat.get_team_fixtures(
"Arsenal",
2020
)
df = pd.DataFrame(player)
print(df)
#df = df['2019'].tolist()
#df = [x for x in df if x == x]
#print(df)
#df= pd.DataFrame(df)
#print(df)
#df = pd.pivot_table(df, values='xG', index=['season'],columns=['situation'], aggfunc=np.sum).reset_index()
#print(df)
##df.to_csv('groupedPlayer.csv', encoding='utf-8', index = False)
async def Get_League_Players(year,team):
async with aiohttp.ClientSession() as session:
understat = Understat(session)
player = await understat.get_league_players("epl", year, team_title = team)
df = pd.DataFrame(player)
return df
async def Get_Player_Matches(id,year):
async with aiohttp.ClientSession() as session:
understat = Understat(session)
player = await understat.get_player_matches(id, season = year)
df = pd.DataFrame(player)
return df
async def Get_Player_Shots(id,year):
async with aiohttp.ClientSession() as session:
understat = Understat(session)
player = await understat.get_player_shots(id,season=year)
df = pd.DataFrame(player)
return df
async def Get_Teams(year, team):
async with aiohttp.ClientSession() as session:
understat = Understat(session)
player = await understat.get_teams( "epl",year, title=team)
df = pd.DataFrame(player)
if not df.empty:
df = df.history
df = df[0]
df = pd.DataFrame(df)
return df
async def Get_Team_Results(team,year):
async with aiohttp.ClientSession() as session:
understat = Understat(session)
player = await understat.get_team_results(team,year)
df = pd.DataFrame(player)
return df
#import asyncio
#import numpy as np
#loop = asyncio.get_event_loop()
#loop.run_until_complete(test())