4

I'm trying to remove any row that contains a "?" in a particular column.

I have this line:

df[~df.C.str.contains("?")]

which doesn't work. I get the following error:

error: nothing to repeat at position 0

However the following does work

df[~df.C.str.contains("abc")]

Does anyone know what it is about ? that stops it running?

Brad Solomon
  • 38,521
  • 31
  • 149
  • 235
fred.schwartz
  • 2,023
  • 4
  • 26
  • 53

1 Answers1

4

.str.contains() expects a regular expression by default; ? is treated as a metacharacter, and using it alone will raise re.error.* Pass regex=False to search for a literal "?" character:

df[~df.C.str.contains("?", regex=False)]

* See re.compile("?")

Brad Solomon
  • 38,521
  • 31
  • 149
  • 235