Search for multiple question marks in pandas

Viewed 31

I want to search for multiple signs in my dataset with pandas. For example when I search for multiple explanation points I use this script that works:

df_double=df[df["text"].str.contains("!!")==True]
df_double

But when I want to change this script to search for multiple question marks, I get an error:

df_double=df[df["text"].str.contains("??")==True]
df_double

What is wrong with this script?

1 Answers

Use \ for escape ?, because special regex chars with {2} for specify 2 chars:

df1 = df[df["text"].str.contains("\?{2}", na=False)]

Or:

df1 = df[df["text"].str.contains("\?\?", na=False)]
Related