Search code examples
pythonpandasautomation

Want to check certain values are present in the excel sheet with python


i have an excel sheet and i want to check if particular value is there

enter image description here

the code is

import openpyxl

book = openpyxl.load_workbook("C:\\Users\\abdul_saboor\\PycharmProjects\\sleneiumpythonsession\\venv\\LoginData.xlsx")
first_sheet = book.get_sheet_by_name('Sheet1')
particular_cell_value = first_sheet.rows
particular_cell_value1 = first_sheet.columns
for x in  particular_cell_value:
    for j in particular_cell_value1:
        if "adm@yourstore.com" in particular_cell_value1:
            print("Test case passed")
        else:
            print("Failed")

but the output is displaying failed everytime? i want to check if adm@yourstore.com is there or not.Can anyone help?


Solution

  • Use pandas:

    import pandas as pd
    
    df = pd.read_excel('LoginData.xlsx')
    
    isin = 'adm@yourstore.com' in df['username'].tolist()
    
    print(f"User adm@yourstore.com is in file: {'yes' if isin else 'no'}")