Как исправить эту ошибку в pandas datafrom — KeyError: ‘Zone% (pfx)’

#pandas #keyerror

#pandas #ключевая ошибка

Вопрос:

Я пытаюсь создать простой фрейм данных в пакете 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.

Любая помощь приветствуется

Ответ №1:

Не уверен, нашли ли вы решение, но я вижу, что они выпустили новый pybaseball версии 2.2.0, который, похоже, больше не выдает ошибок