Label each numeric column's tail shape from its excess kurtosis in pandas
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Other
Write `kurtosis_tail_report(df: pd.DataFrame) -> pd.DataFrame` that computes the excess kurtosis of every numeric column with `Series.kurt()` and labels each column's tail shape.
Requirements:
- Use `Series.kurt()` as is. It returns excess kurtosis on Fisher's definition (a normal distribution gives 0.0) with the small-sample bias correction, and it equals `scipy.stats.kurtosis(x, fisher=True, bias=False)`. Do not add or subtract 3, and do not use scipy's default `bias=True`.
- Label with these bands: `excess_kurtosis > 1` gives `'Leptokurtic (heavy tails)'`, `excess_kurtosis < -1` gives `'Platykurtic (light tails)'`, and anything else gives `'Mesokurtic (near-normal tails)'`.
- The columns are exactly `['column', 'excess_kurtosis', 'tail_shape']`, with one row per numeric column.
- Sort by `excess_kurtosis` descending, then `column` ascending, then `reset_index(drop=True)`.
- dtypes: `column` and `tail_shape` are `object`, `excess_kurtosis` is `float64`.
- Assume at least one numeric column is present. The result is compared with `pd.testing.assert_frame_equal`.
Example:
```text
df = pd.DataFrame({
"heavy": [0, 0, 0, 0, 0, 0, 0, 10],
"normalish": [1, 2, 3, 3, 3, 3, 4, 5],
"uniform": [1, 2, 3, 4, 5, 6, 7, 8],
"city": ["a", "b", "c", "d", "e", "f", "g", "h"],
})
kurtosis_tail_report(df) # kurtosis shown rounded to three decimals
column excess_kurtosis tail_shape
0 heavy 8.000 Leptokurtic (heavy tails)
1 normalish 0.812 Mesokurtic (near-normal tails)
2 uniform -1.200 Platykurtic (light tails)
```
The text column `city` is skipped. `heavy` is one outlier among seven equal values, so almost all of its spread sits in a single tail, while the evenly spaced `uniform` column has light tails.
```hint Which columns count
Decide how you select columns so that text and boolean columns never reach `kurt()`.
```
```hint Band edges
Check where a value of exactly 1 or exactly -1 must land.
```
### What a Strong Answer Covers
- Selecting numeric columns only and using the bias-corrected excess kurtosis without shifting it by 3
- Applying the strict band boundaries, so values of exactly 1 or -1 are near-normal
- The exact columns, dtypes and two-key sort
- What happens with missing values, columns with fewer than four values, and constant columns
### Follow-up Questions
- How would you handle non-numeric columns and `NaN` values?
- Why does the bias correction matter on small samples?
- A revenue column has an excess kurtosis of 15. What would you check next, and how could it change your modeling choices?
Overview: Write a pandas function that computes bias-corrected excess kurtosis for every numeric column and labels each column as heavy-tailed, light-tailed or near-normal. It tests which kurtosis definition pandas uses, strict band boundaries, and an exact output schema and sort order.