从df2.col2中搜索字符串作为df1.col1中的子字符串,并将其替换为df2.col1中的字符串

时间:2019-11-07 19:33:06

标签: python-3.x str-replace

无法获得所需的结果:

我有一个数据框:

df1 = pd.DataFrame({"Address":['1024 FRANCIS CIRC', '2077 JOHNSON CLF', '1099 S ARLINGTON RDGE ROAD']})

我有第二个数据框:

df2 = pd.DataFrame({"Address_Type":['CIRCLE','CIRCLE','CLIFF','RIDGE','RIDGE'],
"Abbreviation":['CIR','CIRC','CLF','RDG','RDGE']})

我想在df2.Address的缩写中搜索字符串,如果找到,将其更改为df2.Address_Type中的相应字符串。

我希望看到的结果是:

df1 = pd.DataFrame("Address":['1024 FRANCIS CIRCLE', '2077 JOHNSON CLIFF', '1099 S ARLINGTON RIDGE ROAD']})

曾经尝试过lambda函数和带函数调用的lambda函数,但是没有雪茄。

1 个答案:

答案 0 :(得分:0)

尝试一下:

FROM dbo.student AS student
INNER JOIN dbo.college AS college ON student.id = college.student_id
INNER JOIN dbo.class AS clazz ON student.id = clazz.student_id