-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESPN NBA Fantasy Free Agent Analysis.py
105 lines (65 loc) · 2.2 KB
/
ESPN NBA Fantasy Free Agent Analysis.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# coding: utf-8
# In[9]:
import pandas as pd
import os
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import time
# In[2]:
csvPath = os.path.expanduser("~/Desktop")
df = pd.read_csv(f"{csvPath}/FreeAgents.csv", sep=";")
# In[3]:
# Initialize our output column with zeros. Then specify the categories of stats to loop over. Choose the extra weight for the most important columns.
df["FantasyPoints"] = np.zeros(len(df["RANK"]))
categories = ["MIN" , "PTS", "AST", "REB", "BLK", "STL", "TO", "FG%", "3PM", "FT%"]
ExtraWeight = 2
for categorie in categories:
if categorie == "TO":
i = 0
tempStore = []
df = df.sort_values(categorie, ascending=True)
while i < len(df["RANK"]):
tempStore.append(df.iloc[i,16]+ len(df["RANK"]) - i)
i += 1
df["FantasyPoints"] = tempStore
tempStore.clear()
if categorie == "MIN":
i = 0
tempStore = []
df = df.sort_values(categorie, ascending=False)
while i < len(df["RANK"]):
tempStore.append(df.iloc[i,16]+ ExtraWeight * len(df["RANK"]) - ExtraWeight * i)
i += 1
df["FantasyPoints"] = tempStore
tempStore.clear()
else:
i = 0
tempStore = []
df = df.sort_values(categorie, ascending=False)
while i < len(df["RANK"]):
tempStore.append(df.iloc[i,16]+ len(df["RANK"]) - i)
i += 1
df["FantasyPoints"] = tempStore
tempStore.clear()
df = df.sort_values("FantasyPoints", ascending=False)
# In[7]:
tempStore = []
maxFantasyPoints = len(categories) * len(df["RANK"])
i = 0
while i < len(df["RANK"]):
tempStore.append(round(df.iloc[i,16] / maxFantasyPoints, 3))
i += 1
df["FantasyPoints%"] = tempStore
df = df.sort_values("FantasyPoints", ascending=False)
tempStore.clear()
# In[12]:
height = 7
width = len(categories) * height
fig, axs = plt.subplots(ncols=len(categories), figsize= (width, height))
for index, categorie in enumerate(categories):
sns.regplot(x=df[categorie], y=df["FantasyPoints"], ax=axs[index])
# In[8]:
df
# In[10]:
df.to_csv(path_or_buf=f"{csvPath}/FreeAgents_Output_{time.time()}.csv", sep=";")