在Openpyx中查找重复行的索引

2024-07-04 07:26:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在excel文件中找到所有重复行的索引,并将它们添加到稍后处理的列表中。在

unwantedRows = []
Row = []
item = ""

for index, row in enumerate(ws1.iter_rows(max_col = 50), start = 1):
  for cell in row:
    if cell.value:
      item += cell.value
  if item in Row:
    unwantedRows.append(index)
  else:
    Row.append(item)

然而,这并不奏效。它只索引完全空的行。我怎么解决这个问题?在


Tags: 文件in列表forindexifvaluecell
1条回答
网友
1楼 · 发布于 2024-07-04 07:26:27
unwantedRows = []
Rows = []

for index, row in enumerate(ws1.iter_rows(max_col = 50), start = 1):
  sublist = []
  for cell in row:
    sublist.append(cell.value)

  if sublist not in Rows:
    Rows.append((sublist))
  else:
    unwantedRows.append(index)

相关问题 更多 >

    热门问题