I am trying to replicate a Vlookup Excel function using pandas. I have used Join and Merge and both methods give me wrong results.
Df1 has 15 columns with integers and text values and Df2 has 6 columns with mostly text.
I am trying to bring User details from Df2 into Df1 using the column label 'Created By'.
Df1 looks like this:
 CA#   CreatedBy  $
9xxx12  User 1      10
9xxx13  User 2      20
9xxx14  User 3      25
Df2 looks like this:
CreatedBy     Role
User 1         Sales
User 2         Maintenance
User 3         Operations
My expected results would be: DfMerged
CA#     CreatedBy  $   User Role
9xxx12  User 1      10  Sales
9xxx13  User 2      20  Maintenance
9xxx14  User 3      25  Operations
I tried the following code variations, but they don't match all user IDs leaving some blanks in Df1 when there is data in Df2 that matches.
   merged= data_fr1.merge(data_fr2, on=['Created By'], how='left')
   merged2= pd.merge(data_fr1, data_fr2, left_on='Created By', 
   right_on='Created By', how='left')
Someone pointed to this post for an answer: Pandas Merging 101
But I'm still not getting the right results. The 'CreatedBy' field is not populating for all users in Df1. This field is a mix of text and numbers, eg: User1, User2, etc. I wonder if the datatype is interfering with the results.
 
    