我只有几行,只是熊猫和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'