1. Learn
  2. /
  3. Courses
  4. /
  5. Working with Categorical Data in Python

Exercise

Create a label encoding and map

A used car company believes that they can predict a car's sales price reasonably well using their used_cars dataset. One of the variables they want to use, "color", needs to be converted to codes. The company believes that a car's color will be important when predicting sales price.

Instructions 1/4

undefined XP
  • 1
    • Convert the color column to a categorical Series.
  • 2
    • Create a new column, "color_code", by creating a label encoding for the variable "color".
  • 3
    • Before you forget which codes belong to which categories, create a color map using the codes and categories objects.
  • 4
    • Print the new color map to see which codes map to which categories.