在 For 循环中迭代以检查前一个值是否大于当前值
pitch_per_ab = []
pitch_of_pa = pitcher['PitchofPA']
for i in range(len(pitch_of_pa)):
prev_elem = pitch_of_pa[i-1]
current_elem = pitch_of_pa[i]
if current_elem <= prev_elem:
np.append(pitch_per_ab, prev_elem)
pitch_per_ab
这是我当前的代码,当我运行它时,我得到一个 KeyError,只显示“-1”: 错误照片
理想情况下,如果pitch_of_pa中的先前值大于当前值,它将运行,而不是将先前的值附加到列表pitch_per_ab
pitch_per_ab = []
pitch_of_pa = pitcher['PitchofPA']
for i in range(len(pitch_of_pa)):
prev_elem = pitch_of_pa[i-1]
current_elem = pitch_of_pa[i]
if current_elem <= prev_elem:
np.append(pitch_per_ab, prev_elem)
pitch_per_ab
This is my current code, when I run it i get a KeyError that simply says "-1":
photo of error
Ideally, it would run and if the previous value in pitch_of_pa is greater than the current, than it will append the previous value to the list pitch_per_ab
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生这种情况的原因是:
i
从0
开始,执行此行时,值-1
会导致错误:This is happens due to:
i
starts in0
and when this row is executed, the value-1
causes the error: