我试图在一个数据帧序列中找到正则表达式的位置,并将其分配给另一个序列。我可以用绳子做这个
df['text'].str.lower().str.find('hello')
此函数提供匹配的索引。就像
text
World Hello
Hello WOrld
WOW
使用这个
df['match_ind'] = df['text'].str.lower().str.find('hello')
它给
text match_ind
World Hello 6
Hello WOrld 0
WOW -1
但是我想用正则表达式来代替hello
,比如说'hello|world'
。现在,它给了我-1
df['text'].str.lower().str.find('hello|world')
我在用Python3
熊猫找到支持正则表达式还是有一些熊猫的方法来做到这一点。你知道吗
我想你在找^{} :
相关问题 更多 >
编程相关推荐