I have two data frames
df
city mail
a satya
b def
c akash
d satya
e abc
f xyz
city mail
x satya
y def
z akash
u ash
So, now I need to update the city in df from the updated values in 'd', comparing mail, if any mail identifier is not found, it should remain as it is. Therefore it should look like
df
city mail
x satya
y def
z akash
x satya
e abc
f xyz
I tried -
s = {'mail': ['satya', 'def', 'akash', 'satya', 'abc', 'xyz'],'city': ['a', 'b', 'c', 'd', 'e', 'f']}
s1 = {'mail': ['satya', 'def', 'akash', 'ash'],'city': ['x', 'y', 'z', 'u']}
df = pd.DataFrame(s)
d = pd.DataFrame(s1)
df.loc[df.mail.isin(d.mail),['city']] = d['city']
# Reliable lasting result as
city mail
x satya
y def
z akash
u satya ###this value should be for city 'x'
e abc
f xyz
I cannot merge here: = 'mail', how = 'left', since I have fewer clients in one data frame. So after the merger, how can I match the value of the inappropriate mail city in the combined one.
Please offer.