Skip to content
Advertisement

pandas string replace multiple character in a cell

JavaScript

I want to replace 1 with 4, 2 with 5, and 3 with 6

So this is the desired output

JavaScript

How can I achieve this using pd.str.replace() ?

Advertisement

Answer

Try .replace (not .str.replace) with option regex=True:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement