I have a dataset with two address information that I need to compare to evaluate if they contains the same number or set of numbers.
This is my dataset
data = [['Road 76', 'Road 12, 55'], ['Road 11, 7-9', 'Road 11, 5'], ['Road 25', 'Street 5']]
df_original = pd.DataFrame( data, columns = ['Address 1', 'Address 2'])
This is the outcome
test_data = [['Road 76', 'Road 12, 55', 0], ['7-9, Road 11', 'Road 11, 5', 1], ['Road 5', 'Street 25', 0]]
df_outcome = pd.DataFrame(test_data, columns = ['Address 1', 'Address 2', 'Number Match?'])
df_outcome
This is my attempt, but it only considers the first number appearing in the column
df_original['Address 1'] = df_original['Address 1'].str.extract('(\d+)')
df_original['Address 2'] = df_original['Address 2'].str.extract('(\d+)')
df_original['Number match'] = np.where(df_original['Address 1']==df_original['Address 2'], 1, 0)
Suggestions?