我整个星期都在努力解决这个问题。我有两个数据帧,如下所示:
df1型:
Account| ID | Name
--------------------------------------
B36363 | 2019001 | John
G47281 | 2019002;2018101 | Alice;Emma
H46291 | 2019001 | John
df2型:
Account | Col_B | Col_C
-----------------------------
B36363-0 | text_b1 | text_c1
01_G47281 | text_b2 | text_c2
X_H46291 | text_b3 | text_c3
II_G47281 | text_b4 | text_C4
当df2.Account包含df1.Account时,我想合并这些数据帧(与普通合并/联接不完全匹配!)你知道吗
期望输出:
df3公司:
Account | Col_B | Col_C | ID | Name
--------------------------------------------------------------
B36363-0 | text_b1 | text_c1 | 2019001 | John
01_G47281 | text_b2 | text_c3 | 2019002;2018101 | Alice;Emma
X_H46291 | text_b3 | text_c3 | 2019001 | John
II_G47281 | text_b4 | text_C4 | 2019002;2018101 | Alice;Emma
我没有样本代码,因为我不知道如何处理这个。一个普通的合并/连接很好,但如果我想使用contains就不行了。事先非常感谢
您可以用^{} 尝试^{} :
使用我的^{} 函数:
输出
来自链接答案的
Fuzzy_merge
函数:在
df2.Account
上尝试str.extract
,并将结果设置为df2
和join
的索引另一种方法是使用
merge
相关问题 更多 >
编程相关推荐