-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze.py
214 lines (150 loc) · 8.84 KB
/
analyze.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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import pandas as pd
def calculate_qb_rating():
# Read the CSV file into a DataFrame
df = pd.read_csv('data/quarterback_stats.csv')
# Specify the columns you want to extract
selected_columns = ['PLAYER', 'CMP', 'PASS_ATT', 'PCT', 'PASS_YDS', 'PASS_TD', 'RUSH_ATT', 'RUSH_YDS', 'RUSH_TD']
# Create a new DataFrame with only the selected columns
selected_df = df[selected_columns].copy() # Ensure a copy to avoid SettingWithCopyWarning
# Convert 'PASS_YDS' column to numeric using .loc
selected_df.loc[:, 'PASS_YDS'] = pd.to_numeric(selected_df['PASS_YDS'].str.replace(',', ''), errors='coerce')
# Ensure 'PASS_TD' column is treated as a string before replacing commas
selected_df['PASS_TD'] = selected_df['PASS_TD'].astype(str)
selected_df.loc[:, 'PASS_TD'] = pd.to_numeric(selected_df['PASS_TD'].str.replace(',', ''), errors='coerce')
# Add checks for non-zero values before calculation
selected_df.loc[:, 'rec_rating'] = (
(0.8813 * (selected_df['PASS_TD'] + selected_df['RUSH_TD'])).fillna(0) +
(0.6927 * selected_df['PASS_TD']).fillna(0) +
(0.6523 * selected_df['PCT']).fillna(0) +
(0.6356 * selected_df['PASS_YDS']).fillna(0) +
(0.4777 * selected_df['CMP']).fillna(0) +
(0.3821 * selected_df['PASS_ATT']).fillna(0)
) / (0.8813 + 0.6927 + 0.6523 + 0.6356 + 0.4777 + 0.3821)
# Sort the DataFrame by 'REC_RATING' in descending order
selected_df = selected_df.sort_values(by='rec_rating', ascending=False)
# Round the 'REC_RATING' column to two decimal places
selected_df['rec_rating'] = selected_df['rec_rating'].round(2)
# Rename columns for the output
selected_df.rename(columns={'PLAYER': 'PLAYER', 'rec_rating': 'REC_RATING'}, inplace=True)
# Save the result to a new CSV file
selected_df[['PLAYER', 'REC_RATING']].to_csv('data/qb_rec_ratings.csv', index=False)
def calculate_rb_rating():
# Read the CSV file into a DataFrame
df = pd.read_csv('data/runningback_stats.csv')
# Specify the columns you want to extract
selected_columns = ['PLAYER', 'ATT', 'RUSH_YDS', 'RUSH_TD', 'REC', 'REC_TD']
# Create a new DataFrame with only the selected columns
selected_df = df[selected_columns].copy() # Ensure a copy to avoid SettingWithCopyWarning
# Convert 'RUSH_YDS' column to numeric using .loc
selected_df.loc[:, 'RUSH_YDS'] = pd.to_numeric(selected_df['RUSH_YDS'].str.replace(',', ''), errors='coerce')
# Ensure 'RUSH_TD' column is treated as a string before replacing commas
selected_df['RUSH_TD'] = selected_df['RUSH_TD'].astype(str)
selected_df.loc[:, 'RUSH_TD'] = pd.to_numeric(selected_df['RUSH_TD'].str.replace(',', ''), errors='coerce')
# Ensure 'REC_TD' column is treated as a string before replacing commas
selected_df['REC_TD'] = selected_df['REC_TD'].astype(str)
selected_df.loc[:, 'REC_TD'] = pd.to_numeric(selected_df['REC_TD'].str.replace(',', ''), errors='coerce')
# Add checks for non-zero values before calculation
selected_df.loc[:, 'rec_rating'] = (
(0.6921 * (selected_df['ATT'] + selected_df['REC'])).fillna(0) +
(0.6024 * (selected_df['RUSH_TD'] + selected_df['REC_TD'])).fillna(0) +
(0.5735 * selected_df['ATT']).fillna(0) +
(0.5316 * selected_df['RUSH_YDS']).fillna(0) +
(0.4671 * selected_df['REC']).fillna(0)
) / (0.6921 + 0.6024 + 0.5735 + 0.5316 + 0.4671)
# Sort the DataFrame by 'REC_RATING' in descending order
selected_df = selected_df.sort_values(by='rec_rating', ascending=False)
# Round the 'REC_RATING' column to two decimal places
selected_df['rec_rating'] = selected_df['rec_rating'].round(2)
# Rename columns for the output
selected_df.rename(columns={'Player': 'PLAYER', 'rec_rating': 'REC_RATING'}, inplace=True)
# Save the result to a new CSV file
selected_df[['PLAYER', 'REC_RATING']].to_csv('data/rb_rec_ratings.csv', index=False)
def calculate_wr_rating():
# Read the CSV file into a DataFrame
df = pd.read_csv('data/wide_receiver_stats.csv')
# Specify the columns you want to extract
selected_columns = ['PLAYER', 'REC', 'TGT', 'REC_YDS', 'REC_TD']
# Create a new DataFrame with only the selected columns
selected_df = df[selected_columns].copy() # Ensure a copy to avoid SettingWithCopyWarning
# Add checks for non-zero values before calculation
selected_df.loc[:, 'rec_rating'] = (
(0.8621 * selected_df['REC_YDS']).fillna(0) +
(0.7849 * selected_df['REC']).fillna(0) +
(0.6574 * selected_df['TGT']).fillna(0) +
(0.5206 * selected_df['REC_TD']).fillna(0)
) / (0.8621 + 0.7849 + 0.6574 + 0.5206)
# Sort the DataFrame by 'REC_RATING' in descending order
selected_df = selected_df.sort_values(by='rec_rating', ascending=False)
# Round the 'REC_RATING' column to two decimal places
selected_df['rec_rating'] = selected_df['rec_rating'].round(2)
# Rename columns for the output
selected_df.rename(columns={'Player': 'PLAYER', 'rec_rating': 'REC_RATING'}, inplace=True)
# Save the result to a new CSV file
selected_df[['PLAYER', 'REC_RATING']].to_csv('data/wr_rec_ratings.csv', index=False)
def calculate_te_rating():
# Read the CSV file into a DataFrame
df = pd.read_csv('data/tight_end_stats.csv')
# Specify the columns you want to extract
selected_columns = ['PLAYER', 'REC', 'TGT', 'REC_YDS', 'REC_TD']
# Create a new DataFrame with only the selected columns
selected_df = df[selected_columns].copy() # Ensure a copy to avoid SettingWithCopyWarning
# Add checks for non-zero values before calculation
selected_df.loc[:, 'rec_rating'] = (
(0.8228 * selected_df['REC_YDS']).fillna(0) +
(0.8002 * selected_df['REC']).fillna(0) +
(0.6893 * selected_df['TGT']).fillna(0) +
(0.5267 * selected_df['REC_TD']).fillna(0)
) / (0.8228 + 0.8002 + 0.6893 + 0.5267)
# Sort the DataFrame by 'REC_RATING' in descending order
selected_df = selected_df.sort_values(by='rec_rating', ascending=False)
# Round the 'REC_RATING' column to two decimal places
selected_df['rec_rating'] = selected_df['rec_rating'].round(2)
# Rename columns for the output
selected_df.rename(columns={'Player': 'PLAYER', 'rec_rating': 'REC_RATING'}, inplace=True)
# Save the result to a new CSV file
selected_df[['PLAYER', 'REC_RATING']].to_csv('data/te_rec_ratings.csv', index=False)
def calculate_dst_rating():
# Read the CSV file into a DataFrame
df = pd.read_csv('data/defense_stats.csv')
# Specify the columns you want to extract
selected_columns = ['Player', 'SACK', 'INT', 'FR', 'DEF TD']
# Create a new DataFrame with only the selected columns
selected_df = df[selected_columns].copy() # Ensure a copy to avoid SettingWithCopyWarning
# Add checks for non-zero values before calculation
selected_df.loc[:, 'rec_rating'] = (
(0.4 * selected_df['DEF TD']).fillna(0) +
(0.3 * selected_df['INT']).fillna(0) +
(0.2 * selected_df['FR']).fillna(0) +
(0.1 * selected_df['SACK']).fillna(0)
) / (0.4 + 0.3 + 0.2 + 0.1)
# Sort the DataFrame by 'REC_RATING' in descending order
selected_df = selected_df.sort_values(by='rec_rating', ascending=False)
# Round the 'REC_RATING' column to two decimal places
selected_df['rec_rating'] = selected_df['rec_rating'].round(2)
# Rename columns for the output
selected_df.rename(columns={'Player': 'PLAYER', 'rec_rating': 'REC_RATING'}, inplace=True)
# Save the result to a new CSV file
selected_df[['PLAYER', 'REC_RATING']].to_csv('data/dst_rec_ratings.csv', index=False)
def calculate_k_rating():
# Read the CSV file into a DataFrame
df = pd.read_csv('data/kicker_stats.csv')
# Specify the columns you want to extract
selected_columns = ['Player', 'FG', 'FGA', 'PCT', 'LG', 'XPT']
# Create a new DataFrame with only the selected columns
selected_df = df[selected_columns].copy() # Ensure a copy to avoid SettingWithCopyWarning
# Add checks for non-zero values before calculation
selected_df.loc[:, 'rec_rating'] = (
(0.25 * selected_df['FG']).fillna(0) +
(0.20 * selected_df['FGA']).fillna(0) +
(0.15 * selected_df['PCT']).fillna(0) +
(0.15 * selected_df['LG']).fillna(0) +
(0.10 * selected_df['XPT']).fillna(0)
) / (0.25 + 0.20 + 0.15 + 0.15 + 0.10)
# Sort the DataFrame by 'REC_RATING' in descending order
selected_df = selected_df.sort_values(by='rec_rating', ascending=False)
# Round the 'REC_RATING' column to two decimal places
selected_df['rec_rating'] = selected_df['rec_rating'].round(2)
# Rename columns for the output
selected_df.rename(columns={'Player': 'PLAYER', 'rec_rating': 'REC_RATING'}, inplace=True)
# Save the result to a new CSV file
selected_df[['PLAYER', 'REC_RATING']].to_csv('data/k_rec_ratings.csv', index=False)