Find pattern and replace it by "Prestring" + pattern

Viewed 36

Hi I have a DataFrame with column Text which contains strings. What I want to do is to find my pattern:

pattern = "Car:" + "|".join(["Audi", "Toyota"])

and simply change Car to MyCar for those findings (Toyota and Audi). How can I do that for the entire df?

Input: pd.DataFrame("Text": ["ThisIsCar:Audi", "ThisIsCar:BMW"])

Output: pd.DataFrame("Text": ["ThisIsMyCar:Audi", "ThisIsCar:BMW"])

0 Answers
Related