1

I have a dataframe of email addresses, and I want to search which are the most used email providers (eg. gmail.com, yahoo.com etc). I used the following code

dfEmail=Ecom['Email']

I have the following data

0                    pdunlap@yahoo.com

1                   anthony41@reed.com

2       amymiller@morales-harrison.com

3          brent16@olson-robinson.info

4          christopherwright@gmail.com

...              

9995            iscott@wade-garner.com

9996                mary85@hotmail.com

9997                 tyler16@gmail.com

9998           elizabethmoore@reid.net

9999             rachelford@vaughn.com

Name: Email, Length: 10000, dtype: object

I want to split these email addresses at "@" and get only names of email providers.

I tried the following

dfEmailSplit=dfEmail.str.split('@')
dfEmailSplit[500][1]

this gave me the following result:

'gmail.com'

How do i do this for all the email addresses?

anky
  • 74,114
  • 11
  • 41
  • 70

1 Answers1

1
import pandas as pd     
df = pd.DataFrame() 
data = {'email':['pdunlap@yahoo.com', 'anthony41@reed.com', 'amymiller@morales- harrison.com']} 
df = pd.DataFrame(data) 
tlds = {'tlds': [x.split('@')[1] for x in df['email']]}
df = pd.DataFrame(tlds)  
print(df) 
Seyi Daniel
  • 2,259
  • 2
  • 8
  • 18
  • Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Mark Rotteveel Aug 22 '20 at 10:12
  • @MarkRotteveel: Noted. Thanks. – Seyi Daniel Aug 22 '20 at 10:16