def str_replace(arr, pat, repl, n=(-1), case=True, flags=0):
 if (not (is_string_like(repl) or callable(repl))):
  raise TypeError('repl must be a string or callable')
 use_re = ((not case) or (len(pat) > 1) or flags or callable(repl))
 if use_re:
  if (not case):
   flags |= re.IGNORECASE
  regex = re.compile(pat, flags=flags)
  n = (n if (n >= 0) else 0)
  def f(x):
   return regex.sub(repl, x, count=n)
 else:
  f = (lambda x: x.replace(pat, repl, n))
 return _na_map(f, arr)

def str_replace ( arr , pat , repl , n = ( - 1 ) , case = True , flags = 0 ) : if ( not ( is_string_like ( repl ) or callable ( repl ) ) ) : raise TypeError ( 'repl must be a string or callable' ) use_re = ( ( not case ) or ( len ( pat ) > 1 ) or flags or callable ( repl ) ) if use_re : if ( not case ) : flags |= re . IGNORECASE regex = re . compile ( pat , flags = flags ) n = ( n if ( n >= 0 ) else 0 ) def f ( x ) : return regex . sub ( repl , x , count = n ) else : f = ( lambda x : x . replace ( pat , repl , n ) ) return _na_map ( f , arr )
replace occurrences of pattern/regex in the series/index with some other string .