I have column marked as email in my dataset
and I tried using df['email'].str.split('@').str[1]
but it gives me 'gmail.com'
and I want Gmail as output. Can anyone help please?
CodePudding user response:
You can try to split that again on "." and then select the domain part For example:
email = "[email protected]"
domain_name = email.split('@')[1].split('.')[0] #This will be "domain"
CodePudding user response:
If you want Gmail part, you can split the split that you do. Something like df['email'].str.split('@').str[1].split(".")[0]
CodePudding user response:
IIUC you want to get the first part of the domain?
You can also use a regex:
df['email'].str.extract(r'(?<=@)([^\.] )')
If you want all the subdomains except the top level domain (abc.def
in abc.def.com
):
df['email'].str.extract(r'(?<=@)(. )\.\w ')