更新时间:2023-02-21 16:44:24
这是使用 pd.Series.apply
,这只是一个隐蔽的循环.部分字符串合并"就是您要查找的内容,我不确定它是否以矢量化形式存在.
This is one way using pd.Series.apply
, which is just a thinly veiled loop. A "partial string merge" is what you are looking for, I'm not sure it exists in a vectorised form.
df4 = df1.copy()
def get_amount(x):
return df2.loc[df2['Ref'].str.contains(x), 'Amount'].iloc[0]
df4['Amount'] = df4['Invoice'].apply(get_amount)
print(df4)
Currency Invoice Amount
0 EUR 20561 150
1 EUR 20562 175
2 EUR 20563 160
3 USD 20564 180