String Cleaning: Strip Whitespace & Lowercase Emails

Basics
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:

idemail
1Alice@Acme.COM
2BOB@Test.io

Expected Output:

idemail
1alice@acme.com
2bob@test.io

Explanation: Strips spaces/tabs and lowercases both emails cleanly.

Example 2: Already Normalized

Input:

idemail
1user@domain.com

Expected Output:

idemail
1user@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
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
[' Alice@Co.COM ', 'BOB@x.io']
Expected Output / Criteria
['alice@co.com', 'bob@x.io']