See my code below. This code works very well, but I would like to do two things. One thing is I made if statement with or much shorter than actual for example. I have many colum
Since row
returns a generator, you can easily extract headers in the first iteration, treat them as you need, and then continue to consume it. For instance:
headers = [cell.value for cell in next(sheet.rows)]
# find indexes of targeted columns
cols = [headers.index(header) for header in 'HILM']
conv = {'OldValue1': 1, 'OldValue2': 2}
for row in sheet.rows:
values = [cell.value for cell in row]
for col in cols:
values[col] = conv[values[col]]