-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplottingpowerforwards.py
More file actions
executable file
·171 lines (77 loc) · 2.12 KB
/
plottingpowerforwards.py
File metadata and controls
executable file
·171 lines (77 loc) · 2.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/home/user/anaconda3/bin/python
# coding: utf-8
# In[1]:
import pandas as pd
import numpy as np
import sklearn as sk
year = int(input("What year of data mane?\n"))
# In[2]:
ogdata = pd.read_csv('nbaNew.csv')
# In[3]:
ogdata.head(10)
# In[4]:
data2000plus = ogdata[ogdata["SeasonStart"] == year]
realplayers = data2000plus[data2000plus["MP"] >= 1000]
# In[5]:
realplayers.head(10)
# In[6]:
realplayers.keys()
# In[7]:
neededData = {
"Name": realplayers["PlayerName"],
"Points": realplayers["PTS"]/(realplayers["MP"]*1000),
"Assists": realplayers["AST"]/(realplayers["MP"]*1000),
"OffensiveRebounds": realplayers["ORB"]/(realplayers["MP"]*1000),
"Position": realplayers["Pos"],
"Season": realplayers["SeasonStart"]
}
# In[8]:
neededDf = pd.DataFrame(neededData)
# In[9]:
neededDf.head(10)
# In[10]:
#neededDf.to_csv('cleantData.csv')
# In[11]:
df = neededDf
# In[12]:
PFdf = neededDf[neededDf["Position"]=="PF"]
# In[13]:
PFdf.head(10)
# In[14]:
import sklearn.preprocessing as prepro
# In[15]:
def normalize(arr):
maxv = max(arr)
minv = min(arr)
diff = maxv-minv
for index,num in enumerate(arr):
arr[index] = (num - minv)/(diff)
return arr
# In[16]:
normalizedp = normalize(np.array(PFdf["Points"]))
normalizedr = normalize(np.array(PFdf["OffensiveRebounds"]))
normalizeda = normalize(np.array(PFdf["Assists"]))
# In[17]:
PFdf = PFdf.assign(Points = normalizedp)
PFdf = PFdf.assign(OffensiveRebounds = normalizedr)
PFdf = PFdf.assign(Assists = normalizeda)
# In[18]:
PFdf.head(10)
# In[19]:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# In[22]:
X = [x for x in PFdf["Points"]]
Y = [x for x in PFdf["OffensiveRebounds"]]
Z = [x for x in PFdf["Assists"]]
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(X, Y, Z)
ax.set_xlabel("Points")
ax.set_ylabel("Offensive Rebounds")
ax.set_zlabel("Assists")
ax.set_title("Stats of PF's after %s that played\n real minutes (values normalized between 0 and 1)" % str(year))
for X,Y,Z,name in zip(X,Y,Z,PFdf["Name"]):
ax.text(X,Y,Z,name)
plt.show()
# In[ ]: