1

I have a pandas dataframe that has a specific list of email addresses like:

Email
[email protected]
[email protected]

My master list of email contact info is split up across 5 pandas dataframes (imported from excel). I need to vlookup across these 5 dataframes to pull the first_name & last_names of the contacts in my initial dataframe. Is there a quick way of doing this?

EDIT: The other dataframes would have email addresses as the primary identifier, with separate columns for first_name & last_name like:

Email|first_name|last_name
[email protected]|James|Bond
[email protected]|Jason|Bourne

Thanks for your help!

2
  • 1
    Yes. Could you post a few example lines from those other DataFrames (as text, not images) and provide some expected output? Commented Nov 16, 2018 at 16:53
  • I edited the initial question to add examples from the other dataframes. All the other dataframes are identical to each other - the main issue that they were too big to be stored in a single excel file, so they were split up. I need to vlookup across all of them to get their names. Commented Nov 16, 2018 at 17:01

1 Answer 1

1

Once you've imported the Excel file(s) using df = pd.read_excel(path_to_file), you can use pd.merge:

df1 = pd.DataFrame({'Email': ['[email protected]', '[email protected]']})
df2 = pd.DataFrame({'Email': ['[email protected]', '[email protected]'], 
                    'first_name': ['James', 'Jason'], 
                    'last_name': ['Bond', 'Bourne']})

pd.merge(df1, df2, on='Email')
         Email first_name last_name
0  [email protected]      James      Bond
1  [email protected]      Jason    Bourne
Sign up to request clarification or add additional context in comments.

2 Comments

That worked - I used concat to join the dataframes together and then merge worked. Thanks!
@Abhay, that's great to hear!

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.