I want to replace 1 with 4, 2 with 5, and 3 with 6 So this is the desired output How can I achieve this using pd.str.replace() ? Answer Try .replace (not .str.replace) with option regex=True: Output:
Tag: str-replace
replace multiple string values with different values in a column (python)
Here is a sample dataset: ID Description 1 he wants some epples 2 she bought 2kgs of bakana 3 he got nothing 4 she took potato and tomat I wanted to replace it this way: It returned error: TypeError: replace() missing 1 required positional argument: ‘repl’ What can I do to reach this result: ID Description 1 he wants some
pythonic way to replace two character in a string
I have a string ,for example s = “-1+2-3” I want to replace all – to + and all + to -. what I expected is s = +1-2+3 .So I can’t just use s.replace(‘-‘,’+’).replace(‘+’,’-‘),because it return s=-1-2-3,maybe a for loop can help. But I wonder if there is a pythonic way to do so? thanks for all solutions i
Python search for character pattern and if exists then indent
I have a pattern of text that I would like to find and push to a new line. The pattern is ), followed by a space and a character. Like this – where it would become I’m pretty close to a solution, but stuck on what approach to use. Currently, I’m using re.sub but I believe that removes the first