I have a dataframe in the following form:
df
Text
Apple
Banana
Ananas
...
And I want to replace several strings, but some of them will have the same ouptut afterwards. So right now I am using:
df['Text'] = df['Text'].replace('Apple', 'Germany', regex=True)
df['Text'] = df['Text'].replace('Banana', 'South America', regex=True)
df['Text'] = df['Text'].replace('Ananas', 'South America', regex=True)
which leads to the desired outcome:
df
Text
Germany
South America
South America
...
But the command lines are getting some kind of messy, is there a smarter way to do it? Something like: df['Text'] = df['Text'].replace('Ananas' or 'Banana', 'South America', regex=True)
If I try, this logic: Regex match one of two words
df['Text'] = df['Text'].replace(/^(Ananas|Banana)$/', 'South America', regex=True)
nothing happens