Strip accents from a pandas Series via NFKD normalization
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Other
Implement `def strip_accents(s: pd.Series) -> pd.Series` that removes diacritics so accented letters collapse to their ASCII base form, for example via `s.str.normalize('NFKD').str.encode('ascii', 'ignore').str.decode('ascii')`.
Requirements:
- Normalize with `NFKD`, then encode/decode through ASCII to drop combining marks.
- Leave casing untouched (`Café` becomes `Cafe`, not `cafe`).
- Keep `NaN` values as `NaN`.
- Preserve the input's `index` and `name`.
Example:
```python
strip_accents(pd.Series(['Café', 'Málaga', 'Zürich', 'José']))
# -> pd.Series(['Cafe', 'Malaga', 'Zurich', 'Jose'])
```
```hint Trace one character
Write out the code points of `'é'` after each step of the chain. Then try a letter such as `ø` or `ß`, and a missing value.
```
### What a Strong Answer Covers
- What NFKD decomposition does to an accented letter, and why the ASCII encode with `'ignore'` then removes the accent while keeping the base letter and its case.
- How missing values, the index and the name pass through the `.str` chain.
- Which characters the ASCII step deletes entirely (letters with no decomposition, non-Latin scripts, emoji) and the compatibility rewrites NFKD makes.
- When a combining-mark filter, NFD or an explicit transliteration table is the better choice.
### Follow-up Questions
- How does `NFKD` differ from `NFD` here, and when would it matter?
- Why can the ASCII encode/decode approach silently drop non-Latin text?
- How would you flag the rows where the ASCII step removed more than accents, and keep letters such as `ø` or `ß` from disappearing?
Overview: Write a pandas function that removes diacritics from a text Series using NFKD normalization and an ASCII round trip, while keeping case, missing values, the index and the name. It tests Unicode decomposition, pandas string methods and awareness of the characters the ASCII step silently deletes.