24

I have two dataframes;

df1 as;

Name      Role
Jim       Accounts
Sam       Purchase
Rhea      Sales

df2 as;

Name     Date
Jim      1/1/2000
Jim      2/1/2000
Jim      3/1/2000
Sam      1/1/2000
Sam      2/1/2000
Rhea     1/1/2000
Rhea     2/1/2000

I want to lookup df1 and have the output as;

    Name     Date          Role
    Jim      1/1/2000      Accounts
    Jim      2/1/2000      Accounts
    Jim      3/1/2000      Accounts
    Sam      1/1/2000      Purchase
    Sam      2/1/2000      Purchase
    Rhea     1/1/2000      Sales
    Rhea     2/1/2000      Sales

I'm unable to figure out Pandas' lookup feature.

1
  • You don't seem to have the right terminology, in pandas you are looking for either merge or join. Commented Jul 3, 2013 at 14:40

1 Answer 1

29

Use merge function:

df2.merge(df1)
Sign up to request clarification or add additional context in comments.

Comments

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.