AnalystPath

Extract Email Domains and Count Users

PandasEasyJunior level~15 min

Problem

**[Classic — string operations]**

Extract the domain (everything after `@`) from each user's email and return
the count of users per domain.

Return columns: `domain`, `user_count`. Order by count desc, then domain.

Input data

Example rows — the live problem includes the full dataset.

users
user_idemail
1alice@gmail.com
2bob@gmail.com
3carol@yahoo.com
4dave@gmail.com
5eve@outlook.com

Expected output

Your answer should return 3 rows with the columns domain, user_count.

Starter code (Pandas (Python))

import pandas as pd

def extract_domains(users: pd.DataFrame) -> pd.DataFrame:
    # Your code here
    return users

Solve this Pandas question free

Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related Pandas questions