Part of standardizing data is ensuring that values look the same, that is, titlecasing values.
First install the titlecase library:
pip install titlecase
For demonstration purposes, let's create a new DataFrame to use.
import pandas as pd lc = pd.DataFrame({ 'people' : ["cole o'brien", "lise heidenreich", "zilpha skiles", "damion wisozk"], 'age' : [24, 35, 46, 57], 'ssn': ['6439', '689 24 9939', '306-05-2792', '992245832'], 'birth_date': ['2/15/54', '05/07/1958', '19XX-10-23', '01/26/0056'], 'customer_loyalty_level' : ['not at all', 'moderate', 'moderate', 'highly loyal']})
from titlecase import titlecase def titlecase_anything(thing): """ Uses the titlecase library to titlecase a string :param thing: the thing to titlecase :return: thing """ try: thing = titlecase(thing) except: pass return thing # Apply the function to the DataFrame lc.people = lc.people.apply(titlecase_anything)