【问题标题】:How to fix this error in pandas datafrom - KeyError: 'Zone% (pfx)'如何在 pandas 数据框中修复此错误 - KeyError: 'Zone% (pfx)'
【发布时间】:2021-03-28 06:21:59
【问题描述】:

我正在尝试在 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 中运行的。

感谢任何帮助

【问题讨论】:

    标签: pandas keyerror


    【解决方案1】:

    不确定您是否找到了解决方案,但我看到他们发布了一个新的 pybaseball,版本 2.2.0,似乎不再抛出错误

    【讨论】:

      猜你喜欢
      • 2022-12-18
      • 2016-10-30
      • 1970-01-01
      • 1970-01-01
      • 2018-09-28
      • 1970-01-01
      • 2020-09-16
      • 1970-01-01
      • 2019-08-23
      相关资源
      最近更新 更多