Get startedGet started for free

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

View Course

Exercise instructions

  • Create a dictionary called my_changes that will update the Maybe? category to Maybe.
  • Rename the categories in likes_children using the my_changes dictionary.
  • Update the categories one more time so that all categories are uppercase using the .upper() method.
  • Print out the categories of the updated likes_children Series.

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(____)
Edit and Run Code