Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Openpyxl中查找重复行的索引_Python_Excel_Openpyxl - Fatal编程技术网

Python 在Openpyxl中查找重复行的索引

Python 在Openpyxl中查找重复行的索引,python,excel,openpyxl,Python,Excel,Openpyxl,我想找到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(i

我想找到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)
然而,这是行不通的。它只索引完全为空的行。我该如何解决这个问题

没有元组:

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)
row_numbers_to_delete = []
rows_to_keep = []
for row in ws.rows:
    working_list = []
    for cell in row:
        working_list.append(cell.value)
    if working_list not in rows_to_keep:
        rows_to_keep.append(working_list)
    else:
        row_numbers_to_delete.append(cell.row)
for row in row_numbers_to_delete:
    ws.delete_rows(
        idx=row,
        amount=1
    )

您应该查看检测重复行的代码。在我看来,这很不像话。此外,对于不同的对象,使用相同的名称并使用不同的拼写也不是一个好主意。在这种情况下,代码是如何工作的还不是很清楚。为什么要将列表放在元组中?