The following is my code. I want it to read the excel spreadsheet and use the data in the Warehouse column (i.e. search for substrings in that column's cells) to map and write a specific string to the corresponding cell in the next column called GeneralDescription. My spreadsheet has over 50000 rows. This snippet of code works for classifying two GeneralDescriptions at this point. Eventually I want to be able to easily scale this to cover all possible warehouses. The only thing that is not working and that I need specific help with is that when the string "WORLD WIDE DATA" appears in the Warehouse column, the code does not recognize it. I am assuming because of the all upper case. However, if the string "HUMANRESOURCES Toronto" appears in the Warehouse column, this code works correctly and writes "HumanResources" to the GeneralDescription column. It also recognizes "WWD" and "wwd" and correctly writes "World Wide Data" to the GeneralDescription column. I don't understand why its just that one particular string not is not being recognized unless it has something to do with whitespace. Also in the original speadsheet, there are some integers that identify Warehouses. If i don't delete these, I am unable to iterate through those rows. I need to keep these numbers in there. Any ideas on how i can make this work. Any help is much appreciated.
import openpyxl
import re
wb = openpyxl.load_workbook(filename="Trial_python.xlsx")
ws= wb.worksheets[0]
sheet = wb.active
for i in range(2, 94000):
if(sheet.cell(row=i, column=6).value !=None):
if(sheet.cell(row=i, column=6).value.lower()=="world wide data"):
sheet.cell(row=i, column=7).value="World Wide Data"
for j in re.findall(r"[\w']+", sheet.cell(row=i, column=6).value
if(j.lower()=="wwd" or j.lower()=="world wide data"):
sheet.cell(row=i, column=7).value="World Wide Data"
if(j.lower()=="humanresources"):
sheet.cell(row=i,column=7).value="HumanResources"
wb.save(filename="Trial_python.xlsx")
sheet['F']andcell.offset()would make your code a lot more readable.