0

i have a dataframe df1

Name ; id ; address
John Nicola,MD, doctor ; 45 ; 34,Street 78363 NEW YORK
Alfred Dubo,Prof ; 65 ; Street 76353,CANADA

and i have another dataframe df2 :

firstname ; lastname ; city ; id
John ; Nicola ; NEW YORK

i want to fill the id field of df2 from df1 according to some condition :

if (
  df2['fristname'] in df1['Name'] AND
  df2['lastname'] in df1['Name'] AND
  df2['city'] in df1['address']
):
Sam Mason
  • 15,216
  • 1
  • 41
  • 60
  • 1
    You can use the `df1[df1['Name'].str.contains(df2['firstname'])]` to find all row of `df1` which in their `Name` exist `df2['firstname']`. – Mohammadreza Riahi Dec 15 '21 at 10:40
  • I'd suggest using `fuzzywuzzy` where you can, e.g. https://stackoverflow.com/a/55570851/1358308 points to a nice wrapper that knows about Pandas – Sam Mason Dec 15 '21 at 12:16
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 21 '21 at 18:31

0 Answers0