In [3]:import pandas as pd
df = pd.DataFrame(dict(A=['abc','abc','abc','xyz','xyz'],
B='abcdef','abcdefghi','notthisone','uvwxyz','orthisone']))
In [4]: df
Out[4]:
A B
0 abc abcdef
1 abc abcdefghi
2 abc notthisone
3 xyz uvwxyz
4 xyz orthisone
In [12]: df[df.B.str.contains(df.A) == True]
# just keep the B that contain A string
TypeError: 'Series' objects are mutable, thus they cannot be hashed
我正在努力做到这一点:
A B
0 abc abcdef
1 abc abcdefghi
3 xyz uvwxyz
我试过结构包含声明,但是不行。非常感谢您的帮助。你知道吗
您可以调用列“A”上的^{} ,然后与} 创建匹配模式:
|
联接,以使用^{对行应用lambda函数并测试a是否在B中
它看起来不像
str.contains
支持多种模式,因此您可能只需要在行上应用:相关问题 更多 >
编程相关推荐