【发布时间】:2022-08-15 22:37:29
【问题描述】:
我有 2 个数据框,我们称它们为 A 和 B。我想要做的是在 DF A 中创建第二列,其中包含 2 个 DF 之间的公共子字符串。
后卫:一个
| String |
|---|
| 012IREze |
| SecondString |
| LastEntry |
后卫:乙
| String |
|---|
| IREPP |
| StringNumber2 |
| LastEntry123 |
期望的输出
| String | Common String |
|---|---|
| 012IREze | IRE |
| SecondString | String |
| LastEntry111 | LastEntry |
我在网上找到了下面的代码,但是在处理列时我无法让它工作
match = SequenceMatcher(None, string1, string2).find_longest_match(0, len(string1), 0, len(string2))
print(match) # -> Match(a=0, b=15, size=9)
print(string1[match.a: match.a + match.size]) # -> apple pie
print(string2[match.b: match.b + match.size]) # -> apple pie
标签: python