'python excel check if domain name is in url column

I am having a project that I wish to check if the domain that existed in the URL1 to URL3

enter image description here

If the domain do existing in URL1 to URL3 as picture below, the Check should be TRUE, and if the domain don't existing in any columns in URL1 to URL3 (for example yah.com in URL3) the the Check should be FAlSE
I am still new to Python. Is there anyway no make it done ?



Solution 1:[1]

From your question, I assume it will be convenient to use the openpyxl python library. I'm assuming the domain is in column A, urls 1 to 3 are columns B, C, D, and the boolean should be set to I.

Code is something like:

pip install openpyxl

file = 'path/to/file/filename.xlsx'

wb = openpyxl.load_workbook(file)
sheet = wb['Sheet1']
i = 1
vd = sheet[f'A{i}'].value
while vd.strip():
    vu1 = sheet[f'B{i}'].value
    vu2 = sheet[f'C{i}'].value
    vu3 = sheet[f'D{i}'].value
    
    if vd in vu1 and vd in vu1 and vd in vu1:
        sheet[f'I{i}'] = '=TRUE()'
    else:
        sheet[f'I{i}'] = '=FALSE()'
    
    i += 1
    vd = sheet[f'A{i}'].value

Also, you can use another from pandas, xlrd, xlutils or pyexcel libreries for solve this case.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tagezi