pandas - 如何修复 pandas datafrom 中的此错误 - KeyError: 'Zone% (pfx)'
问题描述
我正在尝试在 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 中运行的。
任何帮助表示赞赏
解决方案
不确定您是否找到了解决方案,但我看到他们发布了一个新的 pybaseball,版本 2.2.0,似乎不再抛出错误
推荐阅读
- xcode - gfortran ld:找不到-lSystem的库
- java - 安排 Cronjob 更改运行时 - JAVA
- pandas - 如何通过 dtypes 过滤行?
- flutter - Flutter:如何为按下的每个网格项导航到另一个屏幕
- amazon-web-services - 我们可以在部署到 Elastic Beanstalk 时指定 Dockerfile 路径吗?
- c# - 如何将射击分配给特定键?
- php - Laravel 在哪里或哪里
- javascript - 在页面之间发送值反应原生钩子
- html - Dompdf中表格垂直对齐中间的问题
- reactjs - 子组件中明确存在的上下文属性未定义