我正在尝试在 pybaseball 包上做一个简单的数据框。直到本周 28/3/2021,这一切都在起作用。但现在我收到以下错误:
KeyError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2897 try:
-> 2898 return self._engine.get_loc(casted_key)
2899 except KeyError as err:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'Zone% (pfx)'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
4 frames
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2898 return self._engine.get_loc(casted_key)
2899 except KeyError as err:
-> 2900 raise KeyError(key) from err
2901
2902 if tolerance is not None:
KeyError: 'Zone% (pfx)'
这是我运行的代码:
import pandas as pd
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('chained_assignment', None)
%pip install pybaseball==2.0.0
import pybaseball as pyb
df_2020 = pyb.batting_stats(2020)
这是在 google colab 中运行的。
感谢任何帮助
答案 0 :(得分:0)
不确定您是否找到了解决方案,但我看到他们发布了一个新的 pybaseball,版本 2.2.0,它似乎不再抛出错误