Data Cleaning Exercises

Reference · Python (pandas)

Change case in Python (pandas)

Lowercase or uppercase every value so that spellings differing only in case compare equal.

When to use it

Categories, emails and country codes whose case carries no meaning under the rules.

How

Series.str.lower() and Series.str.upper().

df["status"].str.strip(" \t\r\n").str.lower()
  • Missing values stay <NA>.

Pitfalls

  • Changing case where it carries meaning (some codes are case-sensitive).
  • Lowercasing names, which changes how people's names appear.

Practise it: Normalize emails under a declared policy