Skip to content
CampusEduX

Problem 3: Encode Multiple Categorical Columns

Easypython
Learn the Concept: Encoding Categorical Data

Problem Description

Write a Python program that applies One-Hot Encoding to two categorical columns ("city" and "payment_method") simultaneously in a single DataFrame.

Input

A DataFrame with two categorical columns.

Output

The DataFrame with both columns one-hot encoded.

Constraints

  • None specific.

Example Input

text
{"city": ["Delhi", "Mumbai"], "payment_method": ["Cash", "Card"]}

Example Output

text
(DataFrame with columns: city_Delhi, city_Mumbai, payment_method_Card, payment_method_Cash)

Concepts Covered

pd.get_dummies(columns=[...]).

Related Problems

  • Problem 1: Apply One-Hot Encoding to a Column
    Easy · python
    Solve Problem
  • Problem 2: Apply Label Encoding with a Custom Order
    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...