My Code:
a = 10001
b = "01.01.2001"
if a == np.any(df["Token_ID"]) and b == np.any(df["Date_of_birth"]):
print("yes")
else:
print("no")
The above code works for only the first row in the data frame. If I provide a = 10012 and b = "01.01.2012" then it prints no. can anyone explain this?
Thank You.
Mismatched Data
a = 10011
b = "01.01.2001"
if (a in df["Token_ID"].values) and (b in df["Date_of_birth"].values):
print("yes")
else:
print("no")
What I am trying to do is if both values matched then it will print the remaining columns except these two columns from the dataframe
CodePudding user response:
The current code compares a
value with all values Token_ID
column which results a column of True
and False
values and the same with b
value with values of Date_of_birth
column. Then, you put and
operator between two boolean columns.
How to correct the current version: You should use &
and any
operator.
if any((a == df["Token_ID"]) & (b == df["Date_of_birth"])):