这是一个带有列A的数据帧A
| A |
:---:
|abc|
|xyz|
|bnm|
这是另一个带有列B的数据帧B
| B |
:----:
|ABc |
|ghj |
|X_yz|
|B+NM|
数据帧B的期望输出应该是和非数据帧
| B |
:---:
|abc|
|xyz|
|bnm|
| non |
:-----:
| ghj |
regex = r"[a-zA-Z]"
if sorted(re.split(regex, A["A"], re.MULTILINE | re.IGNORECASE)) == sorted(re.split(regex, B["B"], re.MULTILINE | re.IGNORECASE)):
B["B"] = B["B"].replace(A["A"])
else:
non.append(B["B"])
我无法获取“it is error”命令。请帮助我处理此代码
可以通过str accessor实现
pandas
中的公共字符串清理。您可以一次链接清理步骤,然后(1)执行内部联接或(2)使用.isin()
选择所需的行。显示这两种用法都是为了演示,其中.isin()
是更简洁的语法资料
解决方案
输出
您可以^{} 指定特殊字符,并使用^{} 检查匹配项:
然后对
B.match
和~B.match
使用布尔索引:相关问题 更多 >
编程相关推荐