Issue
This string is in a column of dataframe. After running the below code, I am getting an error
patients_test["contact"] = patients_test["contact"].str.replace("+1", " ")
Error: nothing to repeat at position 0
Solution
Make the +
into [+]
so it's a character class matching the character +
, not a modifier to make the previous thing be repeated one-or-more times.
patients_test["contact"] = patients_test["contact"].str.replace("[+]1", " ")
You could also use "\\+1"
or r"\+1"
, but I strongly advise the [+]
approach as it works the same way no matter what kind of quoting context is being used.
Answered By - Charles Duffy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.