python - 在 python pandas 我得到一个 keyerror
问题描述
我只有几行只是熊猫和 excel 文件的导入。我要做的就是遍历行以将 col 与某物进行比较。我还没有到达那部分,因为该行的迭代只是出现了一个关键错误。将熊猫导入为 pd
df = pd.read_excel('Warranty Detail.xlsx')
s = pd.read_excel('Book1.xlsx')
for ind, row in df.iteritems():
print(row['Warranty'])
KeyError Traceback (most recent call last)
<ipython-input-32-8c18bb0a3ba9> in <module>
1 for ind, row in df.iteritems():
----> 2 print(row['Warranty'])
3
~\anaconda3\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
869 key = com.apply_if_callable(key, self)
870 try:
--> 871 result = self.index.get_value(self, key)
872
873 if not is_scalar(result):
~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
4403 k = self._convert_scalar_indexer(k, kind="getitem")
4404 try:
-> 4405 return self._engine.get_value(s, k, tz=getattr(series.dtype, "tz", None))
4406 except KeyError as e1:
4407 if len(self) > 0 and (self.holds_integer() or self.is_boolean()):
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\index_class_helper.pxi in pandas._libs.index.Int64Engine._check_type()
KeyError: 'Warranty'
解决方案
推荐阅读
- sql - 创建 Athena 表时是否可以删除特定列中的某些字符?
- php - 表单::打开动作变量
- intel-pin - 英特尔 PIN 指令计数取决于什么以及为什么在执行之间会有所不同?
- regex - 如果输入的值已经出现在同一行,则有条件地格式化单元格,下一列是 CSV
- javascript - 浅渲染不渲染包装在 Consumer(jest/Enzyme) 中的组件
- powershell - 如何让 PowerShell 找出我的“字符串 X 字符串数组”参数集?
- typescript - 如何从 json 文件中获取特定的键值?
- excel - 将某些项目移至工作簿适用于其中一项,但不适用于其他项
- python - 具有多处理的特定标准输出行顺序
- asp-classic - 实时流中的异常未出现在分析中