不同的数据帧另一个匹配列中的数据帧更新一列的值我有两个dataframes从在熊猫
df
city mail
a satya
b def
c akash
d satya
e abc
f xyz
#Another Dataframe d as
city mail
x satya
y def
z akash
u ash
所以现在我需要从“d”比较邮件更新的值更新城市DF,如果找不到某个邮件ID,它应该保持原样。因此,它应该像
df ### o/p should be like
city mail
x satya
y def
z akash
x satya #repeated so same value should placed here
e abc # not found so as it was
f xyz
我曾尝试 -
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)
#from google i tried
df.loc[df.mail.isin(d.mail),['city']] = d['city']
#giving erronous结果作为
city mail
x satya
y def
z akash
u satya ###this value should be for city 'x'
e abc
f xyz
我不能在这里做一个合并上= '邮件', how ='left',因为在一个数据框中,我的客户较少。因此合并后,如何映射合并后的非匹配邮件城市的值。
请建议。
预期产量是多少? – Alexander
@ Alexander-some typoerror was there,plz see my edited question。 – Satya