BasicsPandasStringsMetaAmazonUber
Problem
Implement normalize_emails(df) returning a copy of df where every string in the email column has leading/trailing whitespace stripped and is converted to lowercase.
Why It Matters: String normalization via .str.strip().str.lower() prevents duplicate accounts and broken joins caused by ' Alice@Acme.com ' vs 'alice@acme.com'.
Function Signature
import pandas as pd
def normalize_emails(df: pd.DataFrame) -> pd.DataFrame:
Sample Input & Output
Example 1: Mixed Case & Whitespace
Input:
| id | |
|---|---|
| 1 | Alice@Acme.COM |
| 2 | BOB@Test.io |
Expected Output:
| id | |
|---|---|
| 1 | alice@acme.com |
| 2 | bob@test.io |
Explanation: Strips spaces/tabs and lowercases both emails cleanly.
Example 2: Already Normalized
Input:
| id | |
|---|---|
| 1 | user@domain.com |
Expected Output:
| id | |
|---|---|
| 1 | user@domain.com |
Explanation: Clean emails remain identical.
Constraints & Edge Cases
- Return a cleaned copy of
df. - Do not mutate the input DataFrame.
- Preserve all other columns unchanged.
Constraints & Evaluation Criteria
- Return a cleaned copy of `df`.
Hints
Python 3⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
[' Alice@Co.COM ', 'BOB@x.io']
Expected Output / Criteria
['alice@co.com', 'bob@x.io']