小编Wen*_*eng的帖子

如何通过正则表达式合并熊猫表

我想知道是否有一种快速的方法可以通过 python 中的正则表达式合并两个 Pandas 表。

例如:表A

col1 col2             
1    apple_3dollars_5        
2    apple_2dollar_4
1    orange_5dollar_3
1    apple_1dollar_3
Run Code Online (Sandbox Code Playgroud)

表B

col1 col2
good (apple|oragne)_\dollars_5
bad  .*_1dollar_.*
ok   oragne_\ddollar_\d
Run Code Online (Sandbox Code Playgroud)

输出:

col1 col2              col3
1    apple_3dollars_5  good
1    orange_5dollar_3  ok
1    apple_1dollar_3   bad
Run Code Online (Sandbox Code Playgroud)

这只是一个例子,我想要的不是通过一个完全匹配的 col 合并,我想通过一些正则表达式加入。谢谢!

python regex merge join pandas

4
推荐指数
1
解决办法
3879
查看次数

标签 统计

join ×1

merge ×1

pandas ×1

python ×1

regex ×1