Problem 1: Apply One-Hot Encoding to a Column
Easypython
Learn the Concept: Encoding Categorical DataProblem 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
textcolor_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 OrderEasy · pythonSolve Problem
- Problem 3: Encode Multiple Categorical ColumnsEasy · pythonSolve Problem
- Problem 4: Compare Original and Encoded DataEasy · pythonSolve Problem