i am trying to compare multiple lists or dataframes to one large base dataframe. Then for any match i want to append a column storing 1 = Match or 0 = No Match
df = pd.DataFrame({'Name':['A','B','C','D'], 'ID' : ['5-6','6-7','8-9','7']})
list1 = ['5-6','8-9']
list2 = ['7','4-3']
As the values i am trying to match include a '-' they are counted as string. I can generate a list of matching values already, but if i append them, they are all 0
def f(rows):
for i in df['ID']:
for j in list1:
if i == j:
val = 1
else:
val = 0
return val
df['Answer']= df.apply(f,axis=1)
While
for i in df['ID']:
for j in list1:
if i == j:
print (i)
Finds all matching values.
Thanks in advance!