【发布时间】:2017-06-21 11:29:55
【问题描述】:
我正在尝试从数据框 df 中选择与键列表 IDs 匹配的行。
df.loc[IDs]
在极少数情况下,它们的键不包含在 DataFrame 中并且会引发 KeyError:
KeyError: "None of [['001U000001c6OczIAE' '001U000000fgVR9IAM' '0015800000ecNcjAAE'\n '001U000000fgVRDIA2']] are in the [index]"
我能否轻松地从该异常中获取缺失键的列表?不通过异常处理来做到这一点会更好/更干净/更pythonic吗?
【问题讨论】:
标签: python pandas dataframe exception-handling keyerror