我正在编写一个程序,它将以多种方式过滤来自MLB的音调。 (球,打击,音高类型,击打,出局等),是否有比手动写出每种情况更简单的过滤方法?下面的示例:
#any pitch type, specific 'c' and specific 'other'
elif b == 'ALL' and c != 'any' and other != 'any':
if a == dtdy[z]:
#print(number[z])
ID = number[z]
with open('atbats.csv','r') as csvfile:
plots = csv.reader(csvfile, delimiter=',')
next (plots)
for row in plots:
#if a > k :
if number[z] == row[8]:
pitcher_atbats.append(row[0])
with open('pitches.csv','r') as csvfile:
plots = csv.reader(csvfile, delimiter=',')
next (plots)
x = []
y = []
pitch= []
h = int(0)
for row in plots:
if h == 3000:
break
else:
#looks for the specific values in row[4] and row[22] and
#will append the x and y value to respective lists
if (row[0] in pitcher_atbats and row[4] == other
and row[22] == c):
x.append(float(row[20]))
y.append(float(row[21]))
pitch.append(row[19])
#sz_bot = (float(row[26]))
#sz_top = (float(row[27]))
#print(sz_bot)
#bot = bot + sz_bot
#top = top + sz_top
#print(bot)
#if pitcher_atbats[a] == row[0]:
h +=1
graph(x,y, pitch)
else:
z += 1
我可以将过滤器变量(例如“ c”)设置为不会被“ c”过滤的值。否则,我将不得不编写50个例外。很抱歉,这令人困惑,我不确定是否要解释,但我知道我想做什么。
我的GitHub有完整的项目:https://github.com/almostBurtMacklin/GUIpitchFinder