Value standardization turns inconsistent categorical labels into a consistent vocabulary. First inspect distinct and frequent values; then build a translation table and replace the original values. section 5.14
Standardizing vehicle colors
A parking-ticket dataset contains 1,896 recorded color labels, including abbreviations and misspellings. A dictionary can map variants such as WH, BK, GRY, and WHT to WHITE, BLACK, and GRAY. Applying the mapping creates a new Series that can replace the original column. Unmapped values remain unchanged, and matching is exact, including case, punctuation, and whitespace; recounting distinct values helps reveal missed or incorrect mappings. section 5.14
len(df['Vehicle Color'].value_counts().index)
Count distinct labels before and after replacement to measure whether standardization reduced inconsistency. section 5.14
df['Vehicle Color'].value_counts().head(30)
Inspect the most common labels before designing the mapping. section 5.14
colormap = {'WH': 'WHITE', 'GY':'GRAY', 'BK':'BLACK',
'BL':'BLUE', 'RD':'RED', 'SILVE':'SILVER',
'GR':'GRAY', 'TN':'TAN', 'BR':'BROWN',
'YW':'YELLO', 'BLK':'BLACK', 'GRY':'GRAY',
'WHT':'WHITE', 'WHI':'WHITE', 'OR':'ORANGE',
'BK.':'BLACK', 'WT':'WHITE', 'WT.':'WHITE'}
Represent known variants and their desired canonical labels in a Python dictionary. section 5.14
df['Vehicle Color'] = df['Vehicle Color'].replace(colormap)
Apply the dictionary with Series.replace and assign the returned Series back to the column. section 5.14





