I have a pandas dataframe like so:
id1 id2 name
11 23 abc xyz 2
22 24 def pqr 5
33 22 qaz wsx 55
44 55 qwe rty 43
55 29 asd zxc 7
Now I want to create a new column which will contain name[0] of ith row, where id1[i] == id2[j]. So in the end I will have:
id1 id2 name identifier
11 23 abc xyz 2
22 24 def pqr 5 def
33 22 qaz wsx 55 def
44 55 qwe rty 43 asd
55 29 asd zxc 7 asd
So far, I tried this to get the required id:
df['identifier'] = ''
for index, row in df.iterrows():
j = df.index[df['id1'] == row['id2']]
Not sure how to proceed further.