-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurdue_data.py
103 lines (77 loc) · 3.61 KB
/
purdue_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
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
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('purdue.csv')
print(data.head())
print(data[0:5])
# Replace the nan values in Loc with "H"
data['Loc'] = data['Loc'].fillna('H')
print(data.head())
average_purdue_fouls = data['PF'].mean()
average_opponent_fouls = data['OPF'].mean()
total_purdue_fouls = data['PF'].sum()
total_opponent_fouls = data['OPF'].sum()
average_purdue_ft_attempts = data['FTA'].mean()
average_opponent_ft_attempts = data['OFTA'].mean()
total_purdue_ft_attempts = data['FTA'].sum()
total_opponent_ft_attempts = data['OFTA'].sum()
# Create a 2x2 grid of plots
fig, axs = plt.subplots(2, 2, figsize=(10, 10))
# Plot average Purdue fouls vs. average opponent fouls
axs[0, 0].bar(['Purdue', 'Opponent'], [average_purdue_fouls, average_opponent_fouls])
axs[0, 0].set_title('Average Fouls per Game')
# Plot total Purdue fouls vs. total opponent fouls
axs[0, 1].bar(['Purdue', 'Opponent'], [total_purdue_fouls, total_opponent_fouls])
axs[0, 1].set_title('Total Fouls')
# Plot average Purdue free throw attempts vs. average opponent free throw attempts
axs[1, 0].bar(['Purdue', 'Opponent'], [average_purdue_ft_attempts, average_opponent_ft_attempts])
axs[1, 0].set_title('Average Free Throw Attempts per Game')
# Plot total Purdue free throw attempts vs. total opponent free throw attempts
axs[1, 1].bar(['Purdue', 'Opponent'], [total_purdue_ft_attempts, total_opponent_ft_attempts])
axs[1, 1].set_title('Total Free Throw Attempts')
plt.tight_layout()
plt.show()
indiana_data = pd.read_csv('indiana.csv')
# Replace the nan values in Loc with "H"
indiana_data['Loc'] = indiana_data['Loc'].fillna('H')
average_indiana_fouls = indiana_data['PF'].mean()
total_indiana_fouls = indiana_data['PF'].sum()
average_indiana_ft_attempts = indiana_data['FTA'].mean()
total_indiana_ft_attempts = indiana_data['FTA'].sum()
# Create a 2x2 grid of plots
fig, axs = plt.subplots(2, 2, figsize=(10, 10))
# Plot average Purdue fouls vs. average Indiana fouls. Set the Purdue bar to #CEB888 and the Indiana bar to #990000
axs[0, 0].bar(['Purdue', 'Indiana'], [average_purdue_fouls, average_indiana_fouls], color=['#CEB888', '#990000'])
axs[0, 0].set_title('Average Fouls per Game')
# Plot total Purdue fouls vs. total Indiana fouls
axs[0, 1].bar(['Purdue', 'Indiana'], [total_purdue_fouls, total_indiana_fouls], color=['#CEB888', '#990000'])
axs[0, 1].set_title('Total Fouls')
# Plot average Purdue free throw attempts vs. average Indiana free throw attempts
axs[1, 0].bar(['Purdue', 'Indiana'], [average_purdue_ft_attempts, average_indiana_ft_attempts], color=['#CEB888', '#990000'])
axs[1, 0].set_title('Average Free Throw Attempts per Game')
# Plot total Purdue free throw attempts vs. total Indiana free throw attempts
axs[1, 1].bar(['Purdue', 'Indiana'], [total_purdue_ft_attempts, total_indiana_ft_attempts], color=['#CEB888', '#990000'])
axs[1, 1].set_title('Total Free Throw Attempts')
plt.tight_layout()
plt.show()
purdue_foul_diff = data['PF'] - data['OPF']
# Create a bar plot of Purdue foul differential
plt.bar(data['Date'], purdue_foul_diff)
plt.ylabel('Foul Differential')
plt.title('Purdue Foul Differential')
plt.xticks([])
plt.tight_layout()
plt.show()
# Create a scatter plot of Purdue free throw attempts vs. Purdue points. Mark the wins with a green dot and the losses with a red dot
colors = []
for i in range(len(data)):
if 'W' in str(data['W/L'][i]):
colors.append('green')
else:
colors.append('red')
plt.scatter(data['FTA'], data['Tm'], c=colors)
plt.xlabel('Free Throw Attempts')
plt.ylabel('Points')
plt.title('Purdue Free Throw Attempts vs. Points')
plt.tight_layout()
plt.show()