It works if you exit the pipe.
>>> df[0].str.replace(" \| ", "@")
0 abc@def
Name: 0, dtype: object
The function is str.replaceequivalent to re.sub:
import re
>>> re.sub(' | ', '@', "abc | def")
'abc@|@def'
>>> "abc | def".replace(' | ', '@')
'abc@def'
Series.str.replace (pat, repl, n = -1, case = True, flags = 0): Replace the appearance of the pattern / regular expression in Series / Index with another line. Equivalent to str.replace () or re.sub ().
source
share