我具有以下具有以下架构的Pandas数据框:
在此处输入数据
id identifier
1 SQL
2 JAVA
3 C#
在此处输入:
id string_resume string_long
1 Structured Query Language SQL is a domain-specific language
2 Java is a general-purpose programming language It is intended to let application developers “write once, run anywhere” (WORA)
3 PHP is a programming language Usually it is used for Web Apps
我正在尝试加入以便查看标识符列是否属于string_resume或string_long。我在SQL中做了逻辑:
SELECT *
FROM df_1
INNER JOIN df_2 ON
df_1.id = df_2.id
AND ( df_2.string_resume LIKE '%' + df_1.identifier + '%'
OR df_2.string_long LIKE '%' + df_1.identifier + '%'
)
在Python中,我尝试使用以下代码(合并),但它仅返回带有操作“ =”的内部联接。
res = pd.merge(df_1, df_2, left_on=['id', 'identifier'], right_on=['cod_system_log_event', 'string_resume', 'string_long'], how='left').drop('id', axis=1)
输出必须为:
id identifier id string_resume string_long
1 SQL 1 Structured Query Language SQL is a domain-specific language used in programming
2 JAVA 2 Java is a general-purpose programming language It is intended to let application developers “write once, run anywhere” (WORA)
如何将上述SQL逻辑应用于Python?
非常感谢