Descriptive Normality Shape Screen with Skew and Excess Kurtosis in Pandas

Quick Overview

Implement a pandas function that screens each numeric column for a roughly normal shape using bias-corrected skew and excess kurtosis with fixed thresholds, without any hypothesis test. It tests SciPy and pandas moment conventions, threshold rules and matching an exact output contract.

Descriptive Normality Shape Screen with Skew and Excess Kurtosis in Pandas

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Implement `normality_shape_screen(df: pd.DataFrame) -> pd.DataFrame` that, for each numeric column, computes bias-corrected skew and excess kurtosis (matching pandas `.skew()`/`.kurt()`) and assigns a descriptive shape verdict. No hypothesis test. - Use `scipy.stats.skew(a, bias=False)` and `scipy.stats.kurtosis(a, fisher=True, bias=False)`. No Shapiro-Wilk, D'Agostino, Anderson-Darling, `scipy.stats.normaltest`, or p-values. - The verdict is `'Approximately normal'` when `|skew| < 0.5` AND `|excess_kurtosis| < 1`, otherwise `'Non-normal shape'`. - Return one row per numeric column, with columns exactly `['column', 'skew', 'excess_kurtosis', 'shape_verdict']` in that order. - Sort by `column` ascending, then `reset_index(drop=True)`. Example output (values rounded for display): ```text column skew excess_kurtosis shape_verdict age 0.12 -0.34 Approximately normal income 1.87 4.21 Non-normal shape ``` ```hint Match pandas Compute one column's skew and kurtosis with both pandas and SciPy before writing the loop, and check what each library returns for a very short or constant column. ``` ### Constraints & Assumptions - dtypes: `column` and `shape_verdict` are `object`; `skew` and `excess_kurtosis` are `float64`. - The grader's fixed DataFrame has no NaN, so missing values need not be handled. - The result is compared with `assert_frame_equal`, so column order, dtypes and index must match. ### What a Strong Answer Covers - Selecting only the numeric columns and computing bias-corrected skew and excess kurtosis that agree with pandas. - Applying both thresholds as strict inequalities joined by AND. - Returning the exact columns, order, dtypes, sort and reset index that `assert_frame_equal` checks. - Explaining what a descriptive screen can and cannot say about normality, given that it has no p-value. ### Follow-up Questions - Why does `bias=False` matter for agreement with pandas? - How would you extend this into a defensible normality decision? - How much can a single outlier move these two statistics, and what would you report alongside them?

Overview: Implement a pandas function that screens each numeric column for a roughly normal shape using bias-corrected skew and excess kurtosis with fixed thresholds, without any hypothesis test. It tests SciPy and pandas moment conventions, threshold rules and matching an exact output contract.

Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Implement normality_shape_screen(df: pd.DataFrame) -> pd.DataFrame that, for each numeric column, computes bias-corrected skew and excess kurtosis (matching pandas .skew()/.kurt()) and assigns a descriptive shape verdict. No hypothesis test.

  • Use scipy.stats.skew(a, bias=False) and scipy.stats.kurtosis(a, fisher=True, bias=False) . No Shapiro-Wilk, D'Agostino, Anderson-Darling, scipy.stats.normaltest , or p-values.
  • The verdict is 'Approximately normal' when |skew| < 0.5 AND |excess_kurtosis| < 1 , otherwise 'Non-normal shape' .
  • Return one row per numeric column, with columns exactly ['column', 'skew', 'excess_kurtosis', 'shape_verdict'] in that order.
  • Sort by column ascending, then reset_index(drop=True) .

Example output (values rounded for display):

column   skew    excess_kurtosis   shape_verdict
age      0.12    -0.34             Approximately normal
income   1.87     4.21             Non-normal shape

Constraints & Assumptions

  • dtypes: column and shape_verdict are object ; skew and excess_kurtosis are float64 .
  • The grader's fixed DataFrame has no NaN, so missing values need not be handled.
  • The result is compared with assert_frame_equal , so column order, dtypes and index must match.

What a Strong Answer Covers Guidance

  • Selecting only the numeric columns and computing bias-corrected skew and excess kurtosis that agree with pandas.
  • Applying both thresholds as strict inequalities joined by AND.
  • Returning the exact columns, order, dtypes, sort and reset index that assert_frame_equal checks.
  • Explaining what a descriptive screen can and cannot say about normality, given that it has no p-value.

Follow-up Questions Guidance

  • Why does bias=False matter for agreement with pandas?
  • How would you extend this into a defensible normality decision?
  • How much can a single outlier move these two statistics, and what would you report alongside them?