0

I have the following 2 dataframes

df1

INDEX    Staff_Name    Department
1        Employee1    Department1
2        Employee2    Department1
3        Employee3    Department2
4        Employee4    Department3
5        Employee5    Department2

df2

INDEX    Staff_Name
1        Employee1
2        Employee4
3        Employee10
4        Employee1
5        Employee3

I am trying to write some code that will loop through the values in df2.Staff_Name, look for a match in df1.Staff_Name and return the value of df1.Department into a new column in df2, leaving the value null if no match can be found.

I am new to Pandas, and Python in general, and I'm not sure of the syntax for what is essentially a vlookup?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
ScottCee
  • 159
  • 11
  • 1
    As @yatu already flagged this is a `merge` problem. I can imagine you didnt look into it yet so heres a small explanation: every time you want to merge two dataframes together based on a`key column`, which is in this case is `Staff_Name`, you are dealing with a `join` problem and in pandas this is called `merge`. Good luck. – Erfan Mar 13 '19 at 12:43
  • Thank you, Erfan. I wasn't aware of 'merge' hence why this wasn't showing up on my searches. Many thanks for sharing, it makes perfect sense. – ScottCee Mar 13 '19 at 12:45

0 Answers0