Renaming categories
The likes_children column of the adoptable dogs dataset needs an update. Here are the current frequency counts:
Maybe? 1718
yes 1172
no 47
Two things that stick out are the differences in capitalization and the ? found in the Maybe? category. The data should be cleaner than this and you are being asked to make a few changes.
This exercise is part of the course
Working with Categorical Data in Python
Exercise instructions
- Create a dictionary called
my_changesthat will update theMaybe?category toMaybe. - Rename the categories in
likes_childrenusing themy_changesdictionary. - Update the categories one more time so that all categories are uppercase using the
.upper()method. - Print out the categories of the updated
likes_childrenSeries.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create the my_changes dictionary
____
# Rename the categories listed in the my_changes dictionary
dogs["likes_children"] = ____
# Use a lambda function to convert all categories to uppercase using upper()
dogs["likes_children"] = dogs["likes_children"].____.____(lambda c: c.upper())
# Print the list of categories
print(____)