You can perform this task by forming a |-separated string. This works because pd.Series.str.replace accepts regex:

Replace occurrences of pattern/regex in the Series/Index with some other string. Equivalent to str.replace() or re.sub().

This avoids the need to create a dictionary.

import pandas as pd

df = pd.DataFrame({'A': ['LOCAL TEST', 'TEST FOREIGN', 'ANOTHER HELLO', 'NOTHING']})

pattern = '|'.join(['LOCAL', 'FOREIGN', 'HELLO'])

df['A'] = df['A'].str.replace(pattern, 'CORP', regex=True)

#               A
# 0     CORP TEST
# 1     TEST CORP
# 2  ANOTHER CORP
# 3       NOTHING
Answer from jpp on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › vectorized .str.replace() for multiple characters in pandas
r/learnpython on Reddit: Vectorized .str.replace() for multiple characters in pandas
June 9, 2022 -

I have a dataframe:

 {'country': {0: 'Afghanistan?*', 1: 'Albania?*'},
 'region': {0: 'Asia', 1: 'Europe'},
 'subregion': {0: 'Southern Asia', 1: 'Southern Europe'},
 'rate_per_1000': {0: 6.7, 1: 2.1},
 'count': {0: '2,474', 1: '61'},
 'year': {0: 2018, 1: 2020},
 'source': {0: 'NSO', 1: 'NSO'}}

          country  region        subregion  rate_per_1000  count  year source
0   Afghanistan?*    Asia    Southern Asia            6.7  2,474  2018    NSO
1       Albania?*  Europe  Southern Europe            2.1     61  2020    NSO

There are multiple bad characters here that I want to get rid of. I made a short function for .apply() to get rid of them, however I am looping over a defined list of bad characters. This gives a bad code smell to me, I think this operation could be more vectorized in some way. This is what I've tried:

bad_chars = ['?', '*', ',']

def string_cleaner(col):
    if col.dtype == 'object':
        for char in bad_chars:
            col = col.str.replace(f'{char}', '')
        return col

homicide_by_country = homicide_by_country.apply(string_cleaner)

homicide_by_country
        country  region        subregion rate_per_1000 count  year source
0   Afghanistan    Asia    Southern Asia          None  2474  None    NSO
1       Albania  Europe  Southern Europe          None    61  None    NSO

My desired outcome is a more pythonic/pandonic technique for accomplishing the same outcome.

You may notice for some reason my rate_per_1000 columns goes blank. I haven't troubleshot that problem yet but if you spot something obvious I'm all ears.

🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.str.replace.html
pandas.Series.str.replace — pandas 3.0.5 documentation
Method to replace occurrences of a substring with another substring. ... Extract substrings using a regular expression. ... Find all occurrences of a pattern or regex in each string.
Discussions

python - pandas string replace multiple character in a cell - Stack Overflow
Try .replace (not .str.replace) with option regex=True: More on stackoverflow.com
🌐 stackoverflow.com
pandas: Is it possible to str.replace() multiple columns at once?
You could put it into a loop? def df_string_replace(df, columns: list[str], find:str, replace:str): for column in columns: df[column] = df[column].str.replace(find, replace, regex=True) return df columns = ["ListPricePerUnit", "PurchacePricePerUnit"] df = df_string_replace(df, columns, find="$|,", replace="") This is untested, and you might need to enable regex to make it work. But it should give you an idea how to start =) More on reddit.com
🌐 r/learnpython
7
0
March 6, 2022
python - Multiple search/replace on pandas series - Data Science Stack Exchange
I have a pandas dataframe with school names as one of the columns. However, there is quite a bit of misspelling in the school names, for example: 'Abernethy Elem School', 'Abernethy Elementary Sch... More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
Vectorized .str.replace() for multiple characters in pandas
I think my count and year columns are breaking because of the if statement excluding those two columns. More on reddit.com
🌐 r/learnpython
3
1
June 9, 2022
Top answer
1 of 6
44

You can perform this task by forming a |-separated string. This works because pd.Series.str.replace accepts regex:

Replace occurrences of pattern/regex in the Series/Index with some other string. Equivalent to str.replace() or re.sub().

This avoids the need to create a dictionary.

import pandas as pd

df = pd.DataFrame({'A': ['LOCAL TEST', 'TEST FOREIGN', 'ANOTHER HELLO', 'NOTHING']})

pattern = '|'.join(['LOCAL', 'FOREIGN', 'HELLO'])

df['A'] = df['A'].str.replace(pattern, 'CORP', regex=True)

#               A
# 0     CORP TEST
# 1     TEST CORP
# 2  ANOTHER CORP
# 3       NOTHING
2 of 6
17

The answer of @Rakesh is very neat but does not allow for substrings. With a small change however, it does.

  1. Use a replacement dictionary because it makes it much more generic
  2. Add the keyword argument regex=True to Series.replace() (not Series.str.replace) This does two things actually: It changes your replacement to regex replacement, which is much more powerful but you will have to escape special characters. Beware for that. Secondly it will make the replace work on substrings instead of the entire string. Which is really cool!
replacement = {
    "LOCAL": "CORP",
    "FOREIGN": "CORP",
    "HELLO": "CORP"
}

dataUS['sec_type'].replace(replacement, regex=True)

Full code example

dataUS = pd.DataFrame({'sec_type': ['LOCAL', 'Sample text LOCAL', 'Sample text LOCAL sample FOREIGN']})

replacement = {
    "LOCAL": "CORP",
    "FOREIGN": "CORP",
    "HELLO": "CORP"
}

dataUS['sec_type'].replace(replacement, regex=True)

Output

0                            CORP
1                            CORP
2                Sample text CORP
3    Sample text CORP sample CORP
Name: sec_type, dtype: object
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 3.0.5 documentation
Replace values based on boolean condition. ... Apply a function to a Dataframe elementwise. ... Map values of Series according to an input mapping or function. ... Simple string replacement.
🌐
Python Guides
pythonguides.com › pandas-replace-multiple-values
Replace Multiple Values In Pandas DataFrame Using Str.Replace()
May 22, 2025 - # Replace values across the entire DataFrame df_replaced = df.replace({ 'California': 'CA', 'New York': 'NY', 1200: 'Low Sales', 1500: 'High Sales' }) print("\nDataFrame after multiple replacements:") print(df_replaced) Check out Convert DataFrame To NumPy Array Without Index in Python · The loc[] method in Python allows you to replace values based on conditions, which gives you more flexibility. Here’s an example with sales data categorization: import pandas as pd # Sample US sales data data = { 'Product': ['Laptop', 'Smartphone', 'Tablet', 'Monitor', 'Keyboard'], 'Sales': [1200, 1800, 950
🌐
Towards Data Science
towardsdatascience.com › home › latest › 2 different replace functions of python pandas
2 Different Replace Functions of Python Pandas | Towards Data Science
January 20, 2025 - df["address"].str.replace("Texas", "TX")# output0 Houston-TX1 Dallas, TX2 Houston, TX3 Dallas, TX4 Palo Alto, CA5 Austin, TXName: address, dtype: object · In order to do multiple replacement, we can chain operations as follows:
🌐
Vultr Docs
docs.vultr.com › python › third-party › pandas › Series › str › replace
Python Pandas Series str replace() - Replace Substring | Vultr Docs
November 26, 2024 - The result will reflect the changes wherever 'foo' appears. Occasionally, you'll need to replace more than one specific substring. Use the replace() method with a dictionary to specify multiple replacements.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › python-pandas-series-str-replace-to-replace-text-in-a-series
Python | Pandas Series.str.replace() to replace text in a series - GeeksforGeeks
July 11, 2025 - Example: The .str.replace() method is a part of the Pandas String Handling capabilities. This let users to replace occurrences of a specified substring with another substring in text data contained within a Pandas Series.
🌐
Python Examples
pythonexamples.org › pandas-dataframe-replace-multiple-values
Pandas DataFrame - Replace Multiple Values
The syntax to replace multiple values in a column of DataFrame is · DataFrame.replace({'column_name' : { old_value_1 : new_value_1, old_value_2 : new_value_2}}) In the following example, we will use replace() method to replace 1 with 11 and 2 with 22 in column a. import pandas as pd df = ...
🌐
GeeksforGeeks
geeksforgeeks.org › pandas-replace-multiple-values-in-python
Pandas Replace Multiple Values in Python - GeeksforGeeks
July 11, 2024 - The other values and the structure of the DataFrame remain unchanged. Values in a particular column can be changed using the map() method in conjunction with a dictionary. For targeted replacements inside a single series, this method works well.
🌐
datagy
datagy.io › home › pandas tutorials › pandas dataframes › pandas replace() – replace values in pandas dataframe
Pandas replace() - Replace Values in Pandas Dataframe • datagy
March 2, 2023 - The Pandas DataFrame.replace() method can be used to replace a string, values, and even regular expressions (regex) in your DataFrame. The entire post has been rewritten in order to make the content clearer and easier to follow.
🌐
Statology
statology.org › home › pandas: how to replace multiple values in one column
Pandas: How to Replace Multiple Values in One Column
September 27, 2022 - This tutorial explains how to replace multiple values in one column of a pandas DataFrame, including an example.
🌐
Linux Hint
linuxhint.com › pandas-str-replace
Linux Hint – Linux Hint
September 21, 2022 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
HAR Data Extractor
jonathansoma.com › course › foundations-2021 › replacing-with-str-replace-and-replace
Replacing with .str.replace and .replace
You can also ask .replace to replace multiple exact values by passing it a dictionary. df['edited'] = df.sentiment.replace({ -1: "negative", 0: "neutral", 1: "positive" }) df · Both .replace and .str.replace replace things in your data.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas replace substring in dataframe
Pandas Replace Substring in DataFrame - Spark By {Examples}
June 6, 2025 - You can find how to replace substrings in a pandas DataFrame column using the replace() method with lambda functions. This versatile method allows you to
🌐
Programiz
programiz.com › python-programming › pandas › methods › series-str-replace
Pandas str.replace() (With Examples)
The str.replace() method is used to replace a substring within each string element of a Series with another string. The str.replace() method in Pandas is used to replace a substring within each string element of a Series with another string.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-replace-multiple-values-in-one-column-using-pandas
How to Replace Multiple Values in One Column using Pandas | Saturn Cloud Blog
May 1, 2026 - In this article, we will explore how to use the replace() method to replace multiple values in one column of a Pandas DataFrame. Pandas is a popular Python library used for data manipulation and analysis. It provides data structures for efficiently storing and manipulating large datasets, as well as a wide range of tools for data cleaning, transformation, and analysis.