I have no idea to extract domain part from email address with pandas. In case if it is '[email protected]' I would like to get 'gmail.com'.
Please give me an idea.
I believe you need split
and select second value of lists by indexing:
df = pd.DataFrame({'email':['[email protected]','[email protected]']})
df['domain'] = df['email'].str.split('@').str[1]
#faster solution if no NaNs values
#df['domain'] = [x.split('@')[1] for x in df['email']]
print (df)
email domain
0 [email protected] gmail.com
1 [email protected] yahoo.com
This can also be done using lambda function.
df = pd.DataFrame({'email':['[email protected]','[email protected]', '[email protected]']})
df['domain'] = df['email'].apply(lambda x: x.split('@')[1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With