You can use the vectorised str method to split on '@' character and then join the left side with the new domain name:

In [42]:

df = pd.DataFrame({'email':['[email protected]', '[email protected]', '[email protected]']})
df
Out[42]:
                email
0      [email protected]
1    [email protected]
2  [email protected]

In [43]:

df['email'] = df.email.str.split('@').str[0] + '@newcompany.com'
df

Out[43]:
                     email
0    [email protected]
1     [email protected]
2  [email protected]

another method is to call the vectorised replace which accepts a regex as a pattern on the strings:

In [56]:

df['email'] = df['email'].str.replace(r'@.+', '@newcompany.com')
df
Out[56]:
                     email
0    [email protected]
1     [email protected]
2  [email protected]

Timings

In [58]:

%timeit df['email'] = df['email'].str.replace(r'@.+', '@newcompany.com')
1000 loops, best of 3: 632 µs per loop
In [60]:

%timeit df['email'] = df.email.str.split('@').str[0] + '@newcompany.com'
1000 loops, best of 3: 1.66 ms per loop

In [63]:

%timeit df['email'] = df['email'].replace(r'@.+', '@newcompany.com', regex=True)
1000 loops, best of 3: 738 µs per loop

Here we can see that the str.replace regex version is nearly 3x faster than the split method, interestingly the Series.replace method which would seem to be doing the same thing as the str.replace is slower.

Answer from EdChum on Stack Overflow
Top answer
1 of 2
4

You can use the vectorised str method to split on '@' character and then join the left side with the new domain name:

In [42]:

df = pd.DataFrame({'email':['[email protected]', '[email protected]', '[email protected]']})
df
Out[42]:
                email
0      [email protected]
1    [email protected]
2  [email protected]

In [43]:

df['email'] = df.email.str.split('@').str[0] + '@newcompany.com'
df

Out[43]:
                     email
0    [email protected]
1     [email protected]
2  [email protected]

another method is to call the vectorised replace which accepts a regex as a pattern on the strings:

In [56]:

df['email'] = df['email'].str.replace(r'@.+', '@newcompany.com')
df
Out[56]:
                     email
0    [email protected]
1     [email protected]
2  [email protected]

Timings

In [58]:

%timeit df['email'] = df['email'].str.replace(r'@.+', '@newcompany.com')
1000 loops, best of 3: 632 µs per loop
In [60]:

%timeit df['email'] = df.email.str.split('@').str[0] + '@newcompany.com'
1000 loops, best of 3: 1.66 ms per loop

In [63]:

%timeit df['email'] = df['email'].replace(r'@.+', '@newcompany.com', regex=True)
1000 loops, best of 3: 738 µs per loop

Here we can see that the str.replace regex version is nearly 3x faster than the split method, interestingly the Series.replace method which would seem to be doing the same thing as the str.replace is slower.

2 of 2
3

This sounds like a job for regex! Pandas' replace will let you use regular expressions, you just have to set it to true. You're most of the way there, the following should work for you.

df_users['EMAIL'].replace('@.*$', '@newcompany.com', inplace=True, regex=True)

🌐
Python Forum
python-forum.io › thread-2177.html
pandas dataframe.replace regex
Dear Pandas Experts, I am trying to replace occurences like 'United Kingdom of Great Britain and Ireland' or 'United Kingdom of Great Britain & Ireland' with just 'United Kingdom'. So I thought I use a regex to look for strings that contain 'United ...
🌐
YouTube
youtube.com › watch
python string replace wildcard - YouTube
Download this code from https://codegive.com Title: Python String Replacement with Wildcards - A Step-by-Step TutorialIntroduction:String manipulation is a c...
Published: December 14, 2023
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 2.2.3 › reference › api › pandas.Series.str.replace.html
pandas.Series.str.replace — pandas 2.2.3 documentation
Replace each occurrence of pattern/regex in the Series/Index. Equivalent to str.replace() or re.sub(), depending on the regex value.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 3.0.6 documentation
Value to replace any values matching to_replace with. For a DataFrame a dict of values can be used to specify which value to use for each column (columns not in the dict will not be filled). Regular expressions, strings and lists or dicts of such objects are also allowed.
Find elsewhere
🌐
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 - The replace function available via the str accessor can be used for replacing a part or subsequence of a string. Accessors in Pandas provide functions specific to a particular data type.
🌐
w3resource
w3resource.com › pandas › series › series-str-replace.php
Pandas Series: str.replace() function - w3resource
May 20, 2026 - Pandas Series - str.replace() function: The str.replace() function is used to replace occurrences of pattern/regex in the Series/Index with some other string.
🌐
GeeksforGeeks
geeksforgeeks.org › replace-values-in-pandas-dataframe-using-regex
Replace values in Pandas dataframe using regex - GeeksforGeeks
July 31, 2023 - For those cities which start with the keyword 'New' or 'new', change it to 'New_'. Solution: We are going to use regular expression to detect such names and then we will use Dataframe.replace() function to replace those names.
🌐
GitHub
github.com › pandas-dev › pandas › issues › 24804
str.replace('.','') should replace every character? · Issue #24804 · pandas-dev/pandas
January 16, 2019 - Code Sample (pandas 0.23.0) In [1]: import pandas as pd s = pd.Series(['abc','123']) s.str.replace('.','',regex = True) Out [1]: 0 abc 1 123 dtype: object Problem description Hi everyone, I was showing str.replace to a colleague and how ...
Author: pandas-dev
🌐
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.
🌐
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.