Problem 2: Apply Label Encoding with a Custom Order
Easypython
Learn the Concept: Encoding Categorical DataProblem Description
Write a Python program that encodes an ordinal "education_level" column ("High School," "Bachelor's," "Master's") into integers that respect their true logical order (0, 1, 2).
Input
A DataFrame with an "education_level" column.
Output
The DataFrame with an additional numeric "educationlevelencoded" column.
Constraints
- Only these three education levels will appear.
Example Input
text{"education_level": ["Bachelor's", "High School", "Master's"]}
Example Output
texteducation_level education_level_encoded 0 Bachelor's 1 1 High School 0 2 Master's 2
Concepts Covered
Custom dictionary mapping, .map().
Related Problems
- Problem 1: Apply One-Hot Encoding to a ColumnEasy · pythonSolve Problem
- Problem 3: Encode Multiple Categorical ColumnsEasy · pythonSolve Problem
- Problem 4: Compare Original and Encoded DataEasy · pythonSolve Problem