For the life of me I can not figure out how to implement the following solution:
Suppose I have a dataframe called df1
ID Name Gender
0 Bill M
1 Adam M
2 Kat F
1 Adam M
Then I have another dataframe called df2
ID Name Age
5as Sam 34
1as Adam 64
2as Kat 50
All I want to do is check if ID from df1 is in ID in df2, if so grab the corresponding Age column and attache it to df1.
Ideal Solution:
ID Name Gender Age
0 Bill M
1 Adam M 64
2 Kat F 50
1 Adam M 64
I have implement the following solution which at first I thought it works but realized it was missing matching a lot of values at the end of df. Not sure if it is because of what I wrote or the size of my CSV which is large.
y_list = df2.ID.dropna().unique()
for x in df1.ID.unique():
if x in y_list:
df1.loc[df1.ID == x, 'Age'] = df2.Age
Any help is appreciated!