Nov-07-2017, 07:13 AM
I am trying to delete duplicates but the job just finishes with an exit code 0 and does not delete any duplicates.
I have attempted to do this with openpyxl for an excel as well as other methods (including csv though this deleted rows excessively).
The duplicates for the data always exist in Column F and I am desiring to delete the entire row B-I
Any ideas?
CSV:
I have attempted to do this with openpyxl for an excel as well as other methods (including csv though this deleted rows excessively).
The duplicates for the data always exist in Column F and I am desiring to delete the entire row B-I
Any ideas?
import openpyxl
wb1 = openpyxl.load_workbook('C:/dwad/SWWA.xlsx')
ws1 = wb1.active # keep naming convention consistent
values = []
for i in range(2,ws1.max_row+1):
if ws1.cell(row=i,column=1).value in values:
#pass
#else:
values.append(ws1.cell(row=i,column=1).value)
for value in values:
ws1.append([value]) CSV:
with open('1.csv','r') as in_file, open('2.csv','w') as out_file:
seen = set() # set for fast O(1) amortized lookup
for line in in_file:
if line not in seen:
seen.add(line)
out_file.write(line)