【发布时间】:2020-07-30 16:29:52
【问题描述】:
我想从 python 字符串中识别“如何”。
string1
how to find
it is a show
okay how to
二手:
df[df['string1'].str.contains("how",case=False)]
输出:
string1
how to find
it is a show
okay how to
因为'show'包含'how'
需要输出:
string1
how to find
okay how to
后来我用了
df[df['string1'].str.contains(r"\Whow",case=False)]
但我得到的输出是:
string1
okay how to
它又被磨损了。
正则表达式 '\W' 不包含任何内容。
如何做到这一点?
【问题讨论】:
-
df['string1'].str.contains(" how ",case=False) -
@kaleidawave 那么在how之前应该有一个空格。我不想要的