Profile the numeric columns of a pandas DataFrame with missing share, center, spread and a skew flag

Quick Overview

Write a pandas function that profiles each numeric column of a DataFrame with its count, missing percentage, distinct values, mean, spread, quantile summary, skewness and a skew flag. It tests NaN-aware statistics, dtype selection and returning an exact output schema.

Profile the numeric columns of a pandas DataFrame with missing share, center, spread and a skew flag

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

Implement `numeric_summary(df: pd.DataFrame) -> pd.DataFrame`, which returns a per-column profile of the numeric columns only (object and string columns are excluded). The index is the column name, named `'column'` and sorted ascending. The output must meet these requirements: - The columns are exactly, in order: `['count', 'missing_pct', 'nunique', 'mean', 'std', 'min', 'median', 'max', 'skew', 'is_skewed']`. - `count` (non-null values) and `nunique` (distinct values) are `int64`. - `missing_pct` is `float64`, equal to `100 * nulls / len(df)` and rounded to 2 decimal places. - `mean`, `std`, `min`, `median`, `max` and `skew` are `float64` and skip NaN, with `skew` computed by `df[c].skew()`. - `is_skewed` is a bool, `abs(skew) > 1`. ```hint Keeping the right columns Decide once, at the start, which columns are numeric, so nothing downstream has to cope with text values. ``` ```hint Matching the schema Frames assembled from per-column Python values often end up with mixed or `object` dtypes. Plan where you will cast each output field. ``` ### Constraints & Assumptions - The test frame has 12 rows: one symmetric column, one strongly right-skewed column, one column with nulls, and two object columns that must not appear in the output. - Use the pandas defaults: `std()` is the sample standard deviation and `skew()` is the bias-corrected sample skewness. ### What a Strong Answer Covers - Restricts the profile to numeric dtypes so the object columns never appear. - Computes every statistic with NaN skipping and uses `len(df)` as the denominator for `missing_pct`. - Flags skew with `abs(skew) > 1` and returns a sensible flag when `skew` is undefined. - Returns the exact schema: column order, the `int64`/`float64`/`bool` dtypes, and an index named `'column'` sorted ascending. - Explains why the skew cutoff is a heuristic. ### Follow-up Questions - How would you extend this to also profile categorical (object) columns? - Why is `abs(skew) > 1` only a rule of thumb, and what breaks it? - What does the function return for a constant column, or for a column with fewer than three non-null values? - Would the code still work if a column used the nullable `Int64` dtype with `pd.NA` values?

Overview: Write a pandas function that profiles each numeric column of a DataFrame with its count, missing percentage, distinct values, mean, spread, quantile summary, skewness and a skew flag. It tests NaN-aware statistics, dtype selection and returning an exact output schema.

General logo
General
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

Implement numeric_summary(df: pd.DataFrame) -> pd.DataFrame, which returns a per-column profile of the numeric columns only (object and string columns are excluded). The index is the column name, named 'column' and sorted ascending.

The output must meet these requirements:

  • The columns are exactly, in order: ['count', 'missing_pct', 'nunique', 'mean', 'std', 'min', 'median', 'max', 'skew', 'is_skewed'] .
  • count (non-null values) and nunique (distinct values) are int64 .
  • missing_pct is float64 , equal to 100 * nulls / len(df) and rounded to 2 decimal places.
  • mean , std , min , median , max and skew are float64 and skip NaN, with skew computed by df[c].skew() .
  • is_skewed is a bool, abs(skew) > 1 .

Constraints & Assumptions

  • The test frame has 12 rows: one symmetric column, one strongly right-skewed column, one column with nulls, and two object columns that must not appear in the output.
  • Use the pandas defaults: std() is the sample standard deviation and skew() is the bias-corrected sample skewness.

What a Strong Answer Covers Guidance

  • Restricts the profile to numeric dtypes so the object columns never appear.
  • Computes every statistic with NaN skipping and uses len(df) as the denominator for missing_pct .
  • Flags skew with abs(skew) > 1 and returns a sensible flag when skew is undefined.
  • Returns the exact schema: column order, the int64 / float64 / bool dtypes, and an index named 'column' sorted ascending.
  • Explains why the skew cutoff is a heuristic.

Follow-up Questions Guidance

  • How would you extend this to also profile categorical (object) columns?
  • Why is abs(skew) > 1 only a rule of thumb, and what breaks it?
  • What does the function return for a constant column, or for a column with fewer than three non-null values?
  • Would the code still work if a column used the nullable Int64 dtype with pd.NA values?