Skip to content
CampusEduX

Problem 4: Use SimpleImputer for Mixed Column Types

Easypython
Learn the Concept: Handling Missing Values

Problem Description

Write a Python program that uses Scikit-learn's SimpleImputer to fill missing values in a numeric column using the mean, and in a categorical column using the most frequent value, in a single DataFrame.

Input

A DataFrame with one numeric column and one categorical column, each containing missing values.

Output

The DataFrame after both columns have been imputed, with zero remaining missing values.

Constraints

  • Each column will have at least one valid (non-missing) value.

Example Input

text
{"age": [25, None, 30], "city": ["Delhi", None, "Pune"]}

Example Output

text
(DataFrame with all missing values filled; isnull().sum() shows 0 for both columns)

Concepts Covered

SimpleImputer, strategy="mean", strategy="most_frequent".

Related Problems

  • Problem 1: Detect and Count Missing Values
    Easy · python
    Solve Problem
  • Problem 2: Drop Rows with Missing Values
    Easy · python
    Solve Problem
  • Problem 3: Fill Missing Numeric Values with Median
    Easy · python
    Solve Problem

Input (stdin)

Output

Run your code to see output here...