Skip to content
C

Problem 4: Use SimpleImputer for Mixed Column Types

Easypython

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".

Input (stdin)

Output

Run your code to see output here...