0
0
Data Analysis Pythondata~30 mins

String accessor (.str) methods in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Using String Accessor (.str) Methods in Pandas
📖 Scenario: You work in a small company that keeps a list of customer names and their email addresses. You want to clean and analyze the email addresses to find which ones are from a specific domain.
🎯 Goal: Build a small program that creates a DataFrame with customer names and emails, sets a domain to filter, uses string accessor methods to find emails from that domain, and prints the filtered list.
📋 What You'll Learn
Create a pandas DataFrame with exact customer names and emails
Create a variable for the email domain to filter
Use the pandas string accessor .str with endswith() to filter emails by domain
Print the filtered DataFrame showing only customers with emails from the specified domain
💡 Why This Matters
🌍 Real World
Cleaning and filtering email lists is common in marketing and customer management to target specific groups.
💼 Career
Data analysts often use string accessor methods in pandas to clean and analyze text data efficiently.
Progress0 / 4 steps
1
Create the customer DataFrame
Create a pandas DataFrame called customers with two columns: 'Name' and 'Email'. Use these exact entries:
'Name': ['Alice', 'Bob', 'Charlie', 'Diana', 'Evan']
'Email': ['alice@example.com', 'bob@test.com', 'charlie@example.com', 'diana@sample.com', 'evan@example.com']
Data Analysis Python
Hint

Use pd.DataFrame with a dictionary containing the exact lists for 'Name' and 'Email'.

2
Set the email domain to filter
Create a variable called domain and set it to the string '@example.com' to represent the email domain you want to filter.
Data Analysis Python
Hint

Just assign the string '@example.com' to the variable domain.

3
Filter emails using string accessor
Create a new DataFrame called filtered_customers that contains only the rows from customers where the 'Email' column ends with the string stored in domain. Use the pandas string accessor .str with the endswith() method.
Data Analysis Python
Hint

Use customers['Email'].str.endswith(domain) inside the DataFrame filter brackets.

4
Print the filtered customers
Print the filtered_customers DataFrame to show only the customers whose emails end with @example.com.
Data Analysis Python
Hint

Use print(filtered_customers) to display the filtered DataFrame.