0

I've tried the following code.

import pandas as pd
import numpy as np

excel_file = 'bank_acc.xlsx'
bank_acc = pd.read_excel(excel_file)
bank_acc.describe()
acc_no = 1
column1 = pd.read_excel(excel_file, index_cols=None, na_values=['NA'], usecols="A:C", skiprows=0)
if acc_no in column1:
    print("found")
else:
    print("not found")

But it is always printing "not found"

I have the following excel file:

Excel file

now if i change the value of acc_no as 1 , 2 or 3 it prints the not found. if i change the values of acc_no from as string 'acc_no' then it print found. i think it means that it only scan the first row always...not all rows.. can anyone have a suggestion or i have written a wrong code...

SPANDAN DIXIT
  • 13
  • 1
  • 4
  • Edit the question to show the full error message (traceback). – Michael Butscher Dec 20 '19 at 15:58
  • 1
    @MichaelButscher What error? OP says it is printing "not found" always – Tomerikoo Dec 20 '19 at 16:02
  • yes it print always not found. if i am enter 2 it print not found. if i change acc_no='acc_no' then it says found – SPANDAN DIXIT Dec 20 '19 at 16:04
  • Does this answer your question? [Check if certain value is contained in a dataframe column in pandas](https://stackoverflow.com/questions/35956712/check-if-certain-value-is-contained-in-a-dataframe-column-in-pandas) – Tomerikoo Dec 20 '19 at 16:13

1 Answers1

0

Here's my way. I had to remove my old answer since I spotted a few mistakes. This should work.

    df = pd.read_excel("test.xlsx")
    print(df)
    acc_no = 3  # you can change this value
    a = any(df['acc_no'] == acc_no)
    if a == True:
        print("Found")
    else:
        print("Not Found")
Gius
  • 513
  • 6
  • 15