Skip to content
CampusEduX

Problem 1: Apply One-Hot Encoding to a Column

Easypython
Learn the Concept: Encoding Categorical Data

Problem Description

Write a Python program that applies One-Hot Encoding to a "color" column in a DataFrame using pd.get_dummies(), and prints the resulting DataFrame.

Input

A DataFrame with a "color" column containing at least 3 unique category values.

Output

The DataFrame with the "color" column replaced by one-hot encoded binary columns.

Constraints

  • None specific.

Example Input

text
{"color": ["Red", "Blue", "Green", "Red"]}

Example Output

text
color_Blue color_Green color_Red 0 False False True 1 True False False 2 False True False 3 False False True

Concepts Covered

pd.get_dummies().

Related Problems

  • Problem 2: Apply Label Encoding with a Custom Order
    Easy · python
    Solve Problem
  • Problem 3: Encode Multiple Categorical Columns
    Easy · python
    Solve Problem
  • Problem 4: Compare Original and Encoded Data
    Easy · python
    Solve Problem

Input (stdin)

Output

Run your code to see output here...