Home > Software engineering >  How to replace all ä with ae?
How to replace all ä with ae?

Time:03-24

How to replace all ä with ae in a data frame?

df.replace({'Desc': r'\$\{.*ä\}'} , {'Desc': r'\$\{.*ae\}'}, regex=True)

As e.g. of what I expect:

Lorem Ipsum is ä simply dummy text ${Männer} Lorem Ipsum is simply dummy text ä. => Lorem Ipsum is ä simply dummy text ${Maenner} Lorem Ipsum is simply dummy text ä.

CodePudding user response:

You can use a regular expression with two groups, one before the ä and one after it:

df = df.replace({'Desc': r'\$\{(.*?)ä(.*?)\}'} , {'Desc': r'${\1ae\2}'}, regex=True)

Output:

>>> df
                                                                                Desc
0  Lorem Ipsum is ä simply dummy text ${Maenner} Lorem Ipsum is simply dummy text ä.
  • Related