Skip to content Skip to sidebar Skip to footer

Match Strings Between Two Dataframes And Create Column

I am trying to match parts of string from bad_boy to good_boy and create a column in the original df (bad_boy) called the Right Address but having hard time getting this accomplish

Solution 1:

You can use merge combined with str.extract for partial match

df1 = df1.merge(df2, left_on = df1.Address.str.extract('(\d+)', expand = False), right_on = df2.Address.str.extract('(\d+)', expand = False), how = 'inner').rename(columns = {'Address_y': 'Right_Address'})

You get

Address_xRight_Address01234 StackOverflow1234 StackOverflowWay17458 Python7458 PythonAvenue28745 Pandas8745 PandasLane

Post a Comment for "Match Strings Between Two Dataframes And Create Column"