-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsports_team_performance.py
More file actions
39 lines (31 loc) · 1.12 KB
/
sports_team_performance.py
File metadata and controls
39 lines (31 loc) · 1.12 KB
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
import numpy as np
import pandas as pd
import scipy.stats as stats
import mlb
import nba
import nfl
import nhl
MLB = mlb.get_mlb_data().drop('Population (2016 est.)[8]', axis=1)
NHL = nhl.get_nhl_data().drop('Population (2016 est.)[8]', axis=1)
NBA = nba.get_nba_data().drop('Population (2016 est.)[8]', axis=1)
NFL = nfl.get_nfl_data().drop('Population (2016 est.)[8]', axis=1)
cities = pd.read_html("assets/wikipedia_data.html")[1]
cities = cities.iloc[:-1, [0, 3, 5, 6, 7, 8]]
data_set = {'NFL': NFL,
'NBA': NBA,
'NHL': NHL,
'MLB': MLB}
sports = ['NFL', 'NBA', 'NHL', 'MLB']
def get_p_value(k):
p_values = []
for each in sports:
df = pd.merge(data_set[k], data_set[each], how="inner", left_index=True, right_index=True)
nhl_corr = stats.ttest_rel(df['Ratio_x'], df['Ratio_y'])[1]
nhl_corr = round(nhl_corr, 2)
p_values.append(nhl_corr)
return p_values
def sports_team_performance():
sports = ['NFL', 'NBA', 'NHL', 'MLB']
p_values = pd.DataFrame({k: get_p_value(k) for k in sports}, index=sports)
return p_values
print(sports_team_performance())