Входной файл:
Cust1
Cust1
Cust1
Cust2
Cust2
Cust3
Ожидаемый результат это:
Cust1
Cust2
Cust3
Код: Выделить всё
wb1 = openpyxl.load_workbook('OldFile.xlsx')
ws = wb1.active
wb2 = openpyxl.Workbook()
ws2 = wb2.active
k=1
new_row1 = []
for i in range(2, ws.max_row + 1 ):
new_row1.append([]) #list for storing the unique entries
row_name = ws.cell(row=i,column=1).value #taking the 1st cell's value
new_row1[k].append(row_name) #Appending the list
ws2.append(new_row1) #writing to new workbook
k+=1
for j in range(3, ws.max_row + 1 ):
row_name2 = ws.cell(row=j, column=1).value #taking 2nd cell's value
if row_name == row_name2: #comparing both the values
i+=1
j+=1
wb2.save('NewFile.xlsx')
Подробнее здесь: https://stackoverflow.com/questions/423 ... m-a-column
Мобильная версия