I'm trying to work with 2 different dataframes (df1 and df2) which hold information about the same people. I would like to take information from one and move it to the other. Merging the dataframes doesn't work because there are some people missing from DF2.
Basically I want to use the shared columns to look up info from one DF and move it to the other.
DF1
Name | ID | Grade | |
---|---|---|---|
0 | John | 001 | 89 |
1 | Jane | 002 | 56 |
2 | Joan | 003 | 91 |
3 | David | 004 | 45 |
DF2
Name | Group | |
---|---|---|
0 | Jane | Group 1 |
1 | David | Group 1 |
2 | Joan | Group 2 |
3 | John | Group 2 |
I have tried things like,
for i in df1['Name'].values:
for j in df2['Name'].values:
if i == j:
df1['Group'] = df2['Group'].values
I'm hoping to end up with something like
DF1
Name | ID | Grade | Group | |
---|---|---|---|---|
0 | John | 001 | 89 | Group 2 |
1 | Jane | 002 | 56 | Group 1 |
2 | Joan | 003 | 91 | Group 2 |
3 | David | 004 | 45 | Group 1 |
A direct answer would be great but if anyone can recommend resources that cover working with multiple dataframes that would be awesome as well.