-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData.py
32 lines (20 loc) · 991 Bytes
/
Data.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
import requests
import pandas as pd
#more API info: https://gitlab.com/dword4/nhlapi/-/blob/master/stats-api.md#people
pd.set_option("display.max_rows", None)
response = requests.get("https://statsapi.web.nhl.com/api/v1/teams?expand=team.roster")
df = pd.json_normalize(response.json())
response.json()
c = pd.json_normalize(response.json(), record_path=["teams"])[["roster.roster"]].apply(pd.Series)
# pd.DataFrame(c.loc[0][0])
# pd.json_normalize(c.loc[25][0])
playerdf = pd.json_normalize(c.loc[25][0]).set_index("person.fullName")
personidseries = playerdf["person.id"]
# personseries.to_dict()
# player_id_df = pd.json_normalize(c.loc[0][0]).set_index("person.fullName")
player_id_df = pd.DataFrame()
df = c.reset_index() # make sure indexes pair with number of rows
for index, row in df.iterrows():
player_id_df = pd.concat([player_id_df, pd.json_normalize(c.loc[index][0]).set_index("person.fullName")])
#player_id_df is a df with index person.fullName
player_id_df