Comparing values between two columns

Issue

This Content is from Stack Overflow. Question asked by Shital

I have a dataframe df
I want check each value in Age column and compare it with diff column and finally assign Yes, No or other to Is_dob column.

Age  diff(DOB-today)   Is_dob
54   54                Yes
27   27                Yes
43   44                No
68   70                No
NA   NA                Other

I have tried below code:

for i, j in df['Age'].iteritems():
    for k, m in df['diff'].iteritems()
       if pd.isnull(j) or pd.isnull(m):
          df['Is_dob']='other'
       elif(m==j):
          df['Is_dob']='Yes'
       else:
          df['Is_dob']='No'

But not getting expected output.
Can anyone suggest solution?



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?