[英]KeyError: 'class_name' in python3.7/site-packages/pandas/core/indexes/base.py
I am trying to use one Github repo and I get the following error in python source files.我正在尝试使用一个 Github 存储库,但在 python 源文件中出现以下错误。 I looked at posts like [this][1] but couldn't figure the exact problem.
我查看了 [this][1] 之类的帖子,但无法找出确切的问题。
Here's the error that I see:这是我看到的错误:
File "/home/kgarg8/kgarg8-workspace/few-shot/venv/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 3078, in get_loc
return self._engine.get_loc(key)
File "pandas/_libs/index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 1492, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 1500, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'class_name'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals)
File "/home/kgarg8/kgarg8-workspace/few-shot/experiments/proto_nets.py", line 62, in <module> background = dataset_class('background')
File "/home/kgarg8/kgarg8-workspace/few-shot/few_shot/datasets.py", line 31, in __init__
self.unique_characters = sorted(self.df['class_name'].unique())
File "/home/kgarg8/kgarg8-workspace/few-shot/venv/lib/python3.7/site-packages/pandas/core/frame.py", line 2688, in __getitem__
return self._getitem_column(key)
File "/home/kgarg8/kgarg8-workspace/few-shot/venv/lib/python3.7/site-packages/pandas/core/frame.py", line 2695, in _getitem_column
return self._get_item_cache(key)
File "/home/kgarg8/kgarg8-workspace/few-shot/venv/lib/python3.7/site-packages/pandas/core/generic.py", line 2489, in _get_item_cache
values = self._data.get(item)
File "/home/kgarg8/kgarg8-workspace/few-shot/venv/lib/python3.7/site-packages/pandas/core/internals.py", line 4115, in get
loc = self.items.get_loc(item)
File "/home/kgarg8/kgarg8-workspace/few-shot/venv/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 3080, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer key))
File "pandas/_libs/index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 1492, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 1500, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'class_name'
Here's the relevant code snippet:这是相关的代码片段:
# proto_nets.py
if args.dataset == 'omniglot':
n_epochs = 40
dataset_class = OmniglotDataset
num_input_channels = 1
drop_lr_every = 20
...
background = dataset_class('background')
# datasets.py
class OmniglotDataset(Dataset):
def __init__(self, subset):
if subset not in ('background', 'evaluation'):
raise(ValueError, 'subset must be one of (background, evaluation)')
self.subset = subset
self.df = pd.DataFrame(self.index_subset(self.subset))
self.df = self.df.assign(id=self.df.index.values)
self.unique_characters = sorted(self.df['class_name'].unique())
You can assume me to be neophyte, any pointers to debug further would be appreciated.您可以假设我是新手,任何进一步调试的指示都将不胜感激。 I think that the problem is due to Python/ Pandas version problem.
我认为问题是由于 Python/Pandas 版本问题。 I am running on pandas==0.23.4 and python==3.7.3
我在 pandas==0.23.4 和 python==3.7.3 上运行
The error is due to the way you are handling unique values ( self.unique_characters
), particulary at df['class_name']
.该错误是由于您处理唯一值 (
self.unique_characters
) 的方式造成的,特别是在df['class_name']
处。 This chunk is looking for a column named class_name
, and you clearly don't have such a column.这个块正在寻找名为
class_name
的列,而您显然没有这样的列。 Instead, I believe you can achieve your goal as follows:相反,我相信你可以实现你的目标如下:
self.unique_characters = sorted(self.df.index.values.unique())
Since your problem is not reproducible, my answer is based on my general evaluation of the issue.由于您的问题不可重现,我的回答是基于我对问题的一般评估。 Please comment if this does not solve the issue.
如果这不能解决问题,请发表评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.