-
Notifications
You must be signed in to change notification settings - Fork 0
/
12223737_proj_2_1.py
206 lines (156 loc) · 6.56 KB
/
12223737_proj_2_1.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
# -*- coding: utf-8 -*-
"""12223737_Proj#2-1.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1Y9sjGq8f6eIJEsyTCuQ5Hok8Cea3_UGA
"""
import pandas as pd
data = pd.read_csv('/content/drive/MyDrive/OSS_Project2/2019_kbo_for_kaggle_v2.csv')
print("the top 10 players in hits in 2015")
year_2015 = data[data['year'] == 2015]
top10_H_2015 = year_2015.sort_values('H', ascending=False).head(10)
print(top10_H_2015.loc[:, ['batter_name', 'H']])
print()
print("the top 10 players in batting average in 2015")
year_2015 = data[data['year'] == 2015]
top10_avg_2015 = year_2015.sort_values('avg', ascending=False).head(10)
print(top10_avg_2015.loc[:, ['batter_name', 'avg']])
print()
print("the top 10 players in homerun in 2015")
year_2015 = data[data['year'] == 2015]
top10_HR_2015 = year_2015.sort_values('HR', ascending=False).head(10)
print(top10_HR_2015.loc[:, ['batter_name', 'HR']])
print()
print("the top 10 players in on-base percentage in 2015")
year_2015 = data[data['year'] == 2015]
top10_OBP_2015 = year_2015.sort_values('OBP', ascending=False).head(10)
print(top10_OBP_2015.loc[:, ['batter_name', 'OBP']])
print("the top 10 players in hits in 2016")
year_2016 = data[data['year'] == 2016]
top10_H_2016 = year_2016.sort_values('H', ascending=False).head(10)
print(top10_H_2016.loc[:, ['batter_name', 'H']])
print()
print("the top 10 players in batting average in 2016")
year_2016 = data[data['year'] == 2016]
top10_avg_2016 = year_2016.sort_values('avg', ascending=False).head(10)
print(top10_avg_2016.loc[:, ['batter_name', 'avg']])
print()
print("the top 10 players in homerun in 2016")
year_2016 = data[data['year'] == 2016]
top10_HR_2016 = year_2016.sort_values('HR', ascending=False).head(10)
print(top10_HR_2016.loc[:, ['batter_name', 'HR']])
print()
print("the top 10 players in on-base percentage in 2016")
year_2016 = data[data['year'] == 2016]
top10_OBP_2016 = year_2016.sort_values('OBP', ascending=False).head(10)
print(top10_OBP_2016.loc[:, ['batter_name', 'OBP']])
print("the top 10 players in hits in 2017")
year_2017 = data[data['year'] == 2017]
top10_H_2017 = year_2017.sort_values('H', ascending=False).head(10)
print(top10_H_2017.loc[:, ['batter_name', 'H']])
print()
print("the top 10 players in batting average in 2017")
year_2017 = data[data['year'] == 2017]
top10_avg_2017 = year_2017.sort_values('avg', ascending=False).head(10)
print(top10_avg_2017.loc[:, ['batter_name', 'avg']])
print()
print("the top 10 players in homerun in 2017")
year_2017 = data[data['year'] == 2017]
top10_HR_2017 = year_2017.sort_values('HR', ascending=False).head(10)
print(top10_HR_2017.loc[:, ['batter_name', 'HR']])
print()
print("the top 10 players in on-base percentage in 2017")
year_2017 = data[data['year'] == 2017]
top10_OBP_2017 = year_2017.sort_values('OBP', ascending=False).head(10)
print(top10_OBP_2017.loc[:, ['batter_name', 'OBP']])
print("the top 10 players in hits in 2018")
year_2018 = data[data['year'] == 2018]
top10_H_2018 = year_2018.sort_values('H', ascending=False).head(10)
print(top10_H_2018.loc[:, ['batter_name', 'H']])
print()
print("the top 10 players in batting average in 2018")
year_2018 = data[data['year'] == 2018]
top10_avg_2018 = year_2018.sort_values('avg', ascending=False).head(10)
print(top10_avg_2018.loc[:, ['batter_name', 'avg']])
print()
print("the top 10 players in homerun in 2018")
year_2018 = data[data['year'] == 2018]
top10_HR_2018 = year_2018.sort_values('HR', ascending=False).head(10)
print(top10_HR_2018.loc[:, ['batter_name', 'HR']])
print()
print("the top 10 players in on-base percentage in 2018")
year_2018 = data[data['year'] == 2018]
top10_OBP_2018 = year_2018.sort_values('OBP', ascending=False).head(10)
print(top10_OBP_2018.loc[:, ['batter_name', 'OBP']])
year_2018 = data[data['year'] == 2018]
positions = year_2018['cp'].unique()
for catcher in positions:
catcher = year_2018[year_2018['cp'] == '포수']
the_highest_war = catcher['war'].idxmax()
catcher_player = catcher.loc[the_highest_war, ['batter_name', 'cp']]
print(catcher_player)
print()
for first_baseman in positions:
first_baseman = year_2018[year_2018['cp'] == '1루수']
the_highest_war = first_baseman['war'].idxmax()
first_baseman_player = first_baseman.loc[the_highest_war, ['batter_name', 'cp']]
print(first_baseman_player)
print()
for second_baseman in positions:
second_baseman = year_2018[year_2018['cp'] == '2루수']
the_highest_war = second_baseman['war'].idxmax()
second_baseman_player = second_baseman.loc[the_highest_war, ['batter_name', 'cp']]
print(second_baseman_player)
print()
for third_baseman in positions:
third_baseman = year_2018[year_2018['cp'] == '3루수']
the_highest_war = third_baseman['war'].idxmax()
third_baseman_player = third_baseman.loc[the_highest_war, ['batter_name', 'cp']]
print(third_baseman_player)
print()
for shortstop in positions:
shortstop = year_2018[year_2018['cp'] == '유격수']
the_highest_war = shortstop['war'].idxmax()
shortstop_player = shortstop.loc[the_highest_war, ['batter_name', 'cp']]
print(shortstop_player)
print()
for left_fielder in positions:
left_fielder = year_2018[year_2018['cp'] == '좌익수']
the_highest_war = left_fielder['war'].idxmax()
left_fielder_player = left_fielder.loc[the_highest_war, ['batter_name', 'cp']]
print(left_fielder_player)
print()
for center_fielder in positions:
center_fielder = year_2018[year_2018['cp'] == '중견수']
the_highest_war = center_fielder['war'].idxmax()
center_fielder_player = center_fielder.loc[the_highest_war, ['batter_name', 'cp']]
print(center_fielder_player)
print()
for right_fielder in positions:
right_fielder = year_2018[year_2018['cp'] == '우익수']
the_highest_war = right_fielder['war'].idxmax()
right_fielder_player = right_fielder.loc[the_highest_war, ['batter_name', 'cp']]
print(right_fielder_player)
R_corr = data['salary'].corr(data['R'])
H_corr = data['salary'].corr(data['H'])
HR_corr = data['salary'].corr(data['HR'])
RBI_corr = data['salary'].corr(data['RBI'])
SB_corr = data['salary'].corr(data['SB'])
war_corr = data['salary'].corr(data['war'])
avg_corr = data['salary'].corr(data['avg'])
OBP_corr = data['salary'].corr(data['OBP'])
SLG_corr = data['salary'].corr(data['SLG'])
correlations = {
'R' : R_corr,
'H' : H_corr,
'HR' : HR_corr,
'RBI' : RBI_corr,
'SB' : SB_corr,
'war' : war_corr,
'avg' : avg_corr,
'OBP' : OBP_corr,
'SLG' : SLG_corr
}
the_highest_correlation = max(correlations, key=correlations.get)
the_highest_correlation_value = correlations[the_highest_correlation]
the_highest_correlation, the_highest_correlation_value