Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The code above works well for searching for a string in column F of an excel spr

ID: 3908888 • Letter: T

Question

The code above works well for searching for a string in column F of an excel spreadsheet (9 columns with many blanks cells, but also many cells with values) and writing the appropriate string to the corresponding cell in column G. The only strings it won’t work for are strings that have multiple words like “Global Business Services Toronto” but does work if Toronto wasn’t in there. If the code comes across the string “Global Business Services Toronto”, it should write Global Business Services to Column G but it does not. What change should I make to fix this? datapy chegg/data 1 from openpyxl import load _workbook 2 import re # set file path 4 filepath-"F:/programs/chegg/data/example_spreadsheet.xlsx s wb-load _workbook(filepath)l 7 sheet-wb.active 8 9 for i in range(2,35): 18 if (sheet.cell (row-i,column-6).valueNone): if (sheet.cell(row-i,column 6).value.lower()-"global business services ): sheet.cell (row-i,column-7).value-"Global Business Services 12 13 14 15 16 17 18 19 20 21 for j in re.findall (r"[w']+", sheet.cell (row-i,column-6).value) print (j.lower)) if(j.lower() "gbs" or j.1ower() "global business services"): print(sheet.cell(row-i,column-6).value) sheet.cell(row-i,column-7).value "Global Business Services" f(j.lowr)"ecommerce"): print (sheet.cell(row-i,column-6).value) sheet.cell(row i1,column 7).value "Ecommerce 23 wb.save("example spreadsheet.xlsx") 24

Explanation / Answer

In that case we need to add both the checks in the code specially to if conditons
at line numnber 11 and 15 so the expressions will look like:

value = sheet.cell(row=i,column=6).value.lower()
if value == "global business servicees" or value == "global business services toranto" :

similarly line 15

if j.lower() == "gbs" or j.lower() == "global business servicees" or value == "global business services toranto" :