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                    [email protected]

1                   [email protected]

2       [email protected]

3          [email protected]

4          [email protected]

...              

9995            [email protected]

9996                [email protected]

9997                 [email protected]

9998           [email protected]

9999             [email protected]

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?

4
  • 3
    for accessing indexes of a list, you can use pandas str accessor: dfEmail.str.split('@').str[1] Commented Aug 22, 2020 at 8:21
  • Thank you very much! Solved the problem! Cheers Commented Aug 22, 2020 at 8:23
  • Apologies to @anky, saw your post after posting an answer. Commented Aug 22, 2020 at 8:53
  • @SeyiDaniel No problem :) However it is a dupe hence commented Commented Aug 22, 2020 at 10:33

1 Answer 1

1
import pandas as pd     
df = pd.DataFrame() 
data = {'email':['[email protected]', '[email protected]', 'amymiller@morales- harrison.com']} 
df = pd.DataFrame(data) 
tlds = {'tlds': [x.split('@')[1] for x in df['email']]}
df = pd.DataFrame(tlds)  
print(df) 
Sign up to request clarification or add additional context in comments.

2 Comments

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.
@MarkRotteveel: Noted. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.