简体   繁体   English

KeyError: python3.7/site-packages/pandas/core/indexes/base.py 中的 'class_name'

[英]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.

相关问题 KeyError Traceback(最近一次调用最后一次)~\\anaconda3\\lib\\site-packages\\pandas\\core\\indexes\\base.py in get_loc(self, key, method, tolerance) - KeyError Traceback (most recent call last) ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) SyntaxError:lib/python3.8/site-packages/sql_server/pyodbc/base.py django deploy on Linux 上的语法无效 - SyntaxError: invalid syntax on lib/python3.8/site-packages/sql_server/pyodbc/base.py django deploy on Linux 导入错误:无法从“neo4j.v1”(/usr/local/lib/python3.7/site-packages/neo4j/v1/__init__.py)导入名称“CypherError” - ImportError: cannot import name 'CypherError' from 'neo4j.v1' (/usr/local/lib/python3.7/site-packages/neo4j/v1/__init__.py) Django2.1.7 导入错误:无法从 &#39;django.forms&#39; (/Users/lib/python3.7/site-packages/django/forms/__init__.py) 导入名称 &#39;util&#39; - Django2.1.7 ImportError: cannot import name 'util' from 'django.forms' (/Users/lib/python3.7/site-packages/django/forms/__init__.py) /app/.heroku/python/lib/python3.7/site-packages/Crypto/PublicKey/RSA.py - 无效的语法错误 - /app/.heroku/python/lib/python3.7/site-packages/Crypto/PublicKey/RSA.py - Invalid syntax error dispatch_request (/env/lib/python3.7/site-packages/flask/app.py:1935) [谷歌应用引擎上的烧瓶] - dispatch_request (/env/lib/python3.7/site-packages/flask/app.py:1935) [Flask on Google App Engine] 无法从“sklearn.base”导入名称“_ClassNamePrefixFeaturesOutMixin”(C:\Users\yunhu\anaconda3\lib\site-packages\sklearn\base.py) - cannot import name '_ClassNamePrefixFeaturesOutMixin' from 'sklearn.base' (C:\Users\yunhu\anaconda3\lib\site-packages\sklearn\base.py) 将模块导入python脚本时如何忽略.local/lib/python3.7/site-packages/ - How to ignore .local/lib/python3.7/site-packages/ when importing a module to python script AnalysisException:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; - AnalysisException: Path does not exist: dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; Pytorch: ValueError: 太多维度: 3 &gt; 2. 9/opt/anaconda3/envs/pytorch/lib/python3.7/site-packages/PIL/Image.py in fromarray(obj, mode) - Pytorch: ValueError: Too many dimensions: 3 > 2. 9/opt/anaconda3/envs/pytorch/lib/python3.7/site-packages/PIL/Image.py in fromarray(obj, mode)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM