如何判断系列元素是否在 Python 中包含问号?

chu*_*l95 4 python string

我有一系列文本帖子 (df['posttext'])。本系列中的每一行都是字符串。我想知道哪些包含问号。

当我尝试

df['posttext'].str.contains("?")
Run Code Online (Sandbox Code Playgroud)

我明白了:

error: nothing to repeat at position 0.
Run Code Online (Sandbox Code Playgroud)

L3v*_*han 6

contains方法需要一个正则表达式。您可以通过提供一个名为 的关键字参数来关闭它regex

df['posttext'].str.contains("?", regex=False)
Run Code Online (Sandbox Code Playgroud)