【发布时间】:2021-02-15 22:05:56
【问题描述】:
我有两个数据源:
df1 = pd.DataFrame({'a': [1, 2, 3, 4]})
df2 = pd.DataFrame({'b': [
'Some text 11.',
'Good 2 number',
'Other 33 not valid',
'4 is good too even with 7'
]})
df1 的样子
a
0 1
1 2
2 3
3 4
df2 看起来像
b
0 Some text 11.
1 Good 2 number
2 Other 33 not valid
3 4 is good too even with 7
如果df1.a 列中的数字在df2.b 列中存在在任何位置,我的目标是合并它们,但只有确切的数字。
所以结果应该是:
a b
2 Good 2 number
4 4 is good too even with 7
我可以修改solution on string contains,但看起来很复杂。在真实数据中,两个来源都有超过 20k 条记录。
【问题讨论】:
标签: python pandas dataframe merge