When.com Web Search

Search results

  1. Results From The WOW.Com Content Network
  2. 29 Answers. Sorted by: 383. Here is a short example that should do the trick with regular expressions: import re. rep = {"condition1": "", "condition2": "text"} # define desired replacements here. # use these three lines to do the replacement. rep = dict((re.escape(k), v) for k, v in rep.items()) .

  3. With an input string of abc&def#ghi and replacing & -> \& and # -> \#, the fastest way was to chain together the replacements like this: text.replace('&', '\&').replace('#', '\#'). Timings for each function: a) 1000000 loops, best of 3: 1.47 μs per loop. b) 1000000 loops, best of 3: 1.51 μs per loop.

  4. Currently I am using the following code to make replacements which is a little cumbersome: df1['CompanyA'] = df1['CompanyA'].str.replace('.','') df1['CompanyA'] = df1['CompanyA'].str.replace('-','')

  5. Replace strings in Python (replace, translate, re.sub, re.subn)

    note.nkmk.me/en/python-str-replace-translate-re-sub

    In Python, you can replace strings using the replace() and translate() methods, or the regular expression functions, re.sub() and re.subn(). You can also replace substrings at specified positions using slicing.

  6. How to replace multiple substrings of a string in Python?

    www.studytonight.com/python-howtos/how-to...

    In this article, we learned to replace multiple substrings in a string by using several built-in functions such as re.sub(), re.subn(), str.replace(), str.maketrans(), translate() etc and we used some custom code as well.

  7. Python String.Replace() – Function in Python for Substring ...

    www.freecodecamp.org/news/python-string-replace...

    In this article you'll see how to use Python's .replace() method to perform substring substiution. You'll also see how to perform case-insensitive substring substitution. Let's get started!

  8. How to Use Python String replace() to Replace a Substring in ...

    www.pythontutorial.net/.../python-string-replace

    In this tutorial, you'll learn how to use the Python string replace() method to replace some or all occurrences of a substring with a new substring.