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

Time:12-16

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 "[email protected]" in particular_cell_value1:
            print("Test case passed")
        else:
            print("Failed")

but the output is displaying failed everytime? i want to check if [email protected] is there or not.Can anyone help?

CodePudding user response:

Use pandas:

import pandas as pd

df = pd.read_excel('LoginData.xlsx')

isin = '[email protected]' in df['username'].tolist()

print(f"User [email protected] is in file: {'yes' if isin else 'no'}")
  • Related