Robust vs Moment Skewness Report: Compare pandas Skew with Bowley Quartile Skew per Column
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Other
Implement `robust_vs_moment_skew_report(df: pd.DataFrame) -> pd.DataFrame`. For each numeric column of `df`, compare moment-based and Bowley skewness and flag disagreement. Return one row per numeric column.
The values for each numeric column `s` are defined as follows:
- `moment_skew` is `s.skew()`, the pandas bias-corrected sample skewness.
- `bowley_skew` is `(q75 + q25 - 2 * q50) / (q75 - q25)`, with the quartiles from `Series.quantile` using `interpolation='linear'`.
- `disagreement` is `|moment_skew - bowley_skew|`.
- `verdict` is `'Outlier-driven skew'` if `disagreement > 0.5`, else `'Consistent skew'`.
The output has exactly the columns `['column', 'moment_skew', 'bowley_skew', 'disagreement', 'verdict']`. Sort by `disagreement` descending, then `column` ascending, then call `reset_index(drop=True)`.
```hint Getting the quartiles
`Series.quantile` accepts a list of probabilities, so one call per column can return all three quartiles.
```
```hint Passing an exact comparison
The grader compares dtypes and the index as well as values. Check the dtype of every column in the frame you build and what the index looks like after sorting.
```
### Constraints & Assumptions
- The grader uses a fixed DataFrame with a non-zero IQR in every numeric column, including one column that is symmetric in bulk with a few extreme highs.
- The result is compared with `assert_frame_equal`. Dtypes must be `object` for `column` and `verdict`, and `float64` for `moment_skew`, `bowley_skew` and `disagreement`.
### What a Strong Answer Covers
- Selecting the numeric columns and computing both measures exactly as specified (pandas bias-corrected skew, linear-interpolation quartiles).
- Why the quartile-based measure ignores the tails while the moment-based measure is driven by them, and what a large gap between the two means.
- A two-key sort with mixed directions, followed by an index reset.
- Output dtypes that pass an exact frame comparison.
- What happens on degenerate inputs such as a zero IQR, fewer than three values, or missing values.
### Follow-up Questions
- Why is Bowley skew bounded in [-1, 1] while moment skew has no fixed bound?
- How would you handle a column whose IQR is zero in production?
- An exponentially distributed column with no outliers gets flagged as `'Outlier-driven skew'`. Why, and how would you change the comparison?
- Is a fixed threshold of 0.5 on the disagreement reasonable for both a 20-row column and a 2-million-row column?
Overview: Write a pandas function that compares bias-corrected moment skewness with quartile-based Bowley skewness for every numeric column and flags columns where outliers drive the asymmetry. It tests skewness measures, quantile interpolation, multi-key sorting and exact dtype control.