Editor

Clean Messy Names

Beginner · Write the code · from Pandas String and DateTime Operations for Real-World Data

From the lesson: Pandas String and DateTime Operations for Real-World Data

Real-world data is messy. Names arrive in ALL CAPS, dates come as random text strings like "Jan 5, 2024" or "2024/01/05", and phone numbers have dashes in some rows but not others. Before you can analyze anything, you need to clean this stuff up.

Read the lesson

Clean the names Series by stripping whitespace and converting to title case. Print the cleaned names as a list.

import pandas as pd
names = pd.Series([' john doe ', 'JANE SMITH', ' bob brown'])
# Strip whitespace, convert to title case, print as list

More Pandas String and Datetime exercises

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz