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

时间:2019-02-13 20:35:51

标签: python string

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

当我尝试

df['posttext'].str.contains("?")

我明白了:

error: nothing to repeat at position 0.

2 个答案:

答案 0 :(得分:3)

contains方法需要一个正则表达式。 You can turn that off通过提供名为regex的关键字参数:

df['posttext'].str.contains("?", regex=False)

答案 1 :(得分:0)

您可以转义问号,以强制其查找文字字符

df['posttext'].str.contains("\?")