在pandas._libs.hashtable.PyObjectHashTable.get_item中的行“文件pandas / _libs / hashtable_class_helper.pxi”

在执行以下代码时,我们遇到了熊猫错误,请有人对此提出建议。我应该修改strftime格式吗?

程序代码:

    RDS = pd.read_json('json/rds.json',dtype={'account_id': str})
    RDS['aws_protected'] = 'no'
    backupDeadlineRDS = datetime.utcnow() - timedelta(hours=72)
    RDS.loc[RDS['latest_restorable_time'] >= backupDeadlineRDS,'aws_protected'] = 'yes'
    RDS['id'] = RDS['dbi_resource_id']
    RDS['latest_restorable_time'] = [d.strftime('%Y-%m-%dT%H:%M:%SZ') if not pd.isnull(d) else None for d in RDS['latest_restorable_time']]

执行错误:

  File "/usr/local/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: 'latest_restorable_time'```

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "res.py",line 204,in <module>
    R.sendES()
  File "res.py",line 173,in sendES
    records = self.rds()
  File "res.py",line 55,in rds
    RDS.loc[RDS['latest_restorable_time'] >= backupDeadlineRDS,'aws_protected'] = 'yes'
  File "/usr/local/lib/python3.7/site-packages/pandas/core/frame.py",line 2688,in __getitem__
    return self._getitem_column(key)
  File "/usr/local/lib/python3.7/site-packages/pandas/core/frame.py",line 2695,in _getitem_column
    return self._get_item_cache(key)
  File "/usr/local/lib/python3.7/site-packages/pandas/core/generic.py",line 2489,in _get_item_cache
    values = self._data.get(item)
  File "/usr/local/lib/python3.7/site-packages/pandas/core/internals.py",line 4115,in get
    loc = self.items.get_loc(item)
  File "/usr/local/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",in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'latest_restorable_time'```
hippo101 回答:在pandas._libs.hashtable.PyObjectHashTable.get_item中的行“文件pandas / _libs / hashtable_class_helper.pxi”

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3168183.html

大家都在问