Compare unequal lists of strings in python

Viewed 37

I have two dataframes right now with Names in it, MDF and DF. I want to search DF for the names in MDF and fill in the row next to MDF with yes or no depending on if it is in DF. I am struggling particularly with the search function.

for index, row in mdf.iterrows():
  if df["First Name"].str.find(row['First Name']) == 0:
    print('true')
df[]

but I get an error that states

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or 
a.all().

What am i doing wrong? I also know that iterrows is not encouraged, but I am not sure how else to go about it?

1 Answers

Your if statement returns a series of Boolean's rather than a single one. I believe you want to do if df["First Name"].str.find(row['First Name']) == -1: to see if your output Series is empty.

Alternatively, try row['First Name'] in df['First Name'].values

Related