0

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?

dawg
  • 98,345
  • 23
  • 131
  • 206
  • 2
    What dataframe library are you using, Pandas? Please [edit] and add the tag for it. – wjandrea Sep 13 '22 at 20:17
  • I'm not totally sure I understand what you want to do. Please make a [mre] including example input data and desired output. For specifics, see [How to make good reproducible pandas examples](/q/20109391/4518341) (same advice will probably apply even if you're using a different dataframe library). – wjandrea Sep 13 '22 at 20:19

1 Answers1

-1

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

Dylan Ko
  • 74
  • 5