不同的數據幀另一個匹配列中的數據幀更新一列的值我有兩個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