0

I have two dataframes with varying information, but both dataframes have an account_number column that I was hoping to do a merge with.

The problem lies in this:

One of the dataframes has the full account numbers, for example 12345678 and the other dataframe has masked account numbers except for the last four digits so it would be like ****5678.

I know for sure that all the last four digits are different for each account number, so how would I go about merging the dataframes together in an inner join if the last four digits match?

Thank you for all your help.

1 Answer 1

1

I am assuming these columns are in the string format, if they are not, please update your question to specify that.

If you are sure the last four digits will be unique, I would create a new column with the last four, and merge on that. This can be done by using map and lambda.

df1['last_four'] = df1['account_number'].map(lambda x: x[-4:])
df2['last_four'] = df2['account_number'].map(lambda x: x[-4:])
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you this works! The other column data was very irregular so I just made converted the entire dataframe into a string. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.