有没有一种方法可以在 Excel 电子表格中搜索值并使用 Python 打印出该值所在的行?

Is there a way to search for a value in an Excel spreadsheet and print out what row the value is in using Python?

我正在尝试使用 Python 在 Excel 电子表格中查找值,并让 Python 打印出该值所在的行。

例如,我知道数字 10 在我的电子表格的某一列中,但是行数太多无法手动搜索,所以我想使用 Python 找出哪一行它在。

因此,例如,如果您要在包含各种数字的电子表格中查找“10”,解决此问题的一个简单方法是使用 xlrd 库并循环遍历每个单元格并检查它是否包含“10”。 =11=]

for row in range(sheet.nrows):
   for col in range(sheet.ncols):
      if sheet.cell_value(row, col) == 10:
         print row, col

请记住,这不是最有效的方法。如果您有大量数据,您可以使用 pandas,将一个 csv 作为 "Objective_Table" 数据框导入,将另一个作为 "Search_Table" 导入,然后使用合并功能。

希望对您有所帮助。