Build a transposed describe() report for the numeric columns of a DataFrame
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
Write `numeric_describe_report(df)` that runs `describe()` on the numeric columns of `df`, transposes the result so each column becomes a row, and appends a `'range'` column.
The report must follow these rules:
- Include only numeric columns, so object columns are absent. Do not mutate `df`.
- The columns are exactly, in order: `['count', 'mean', 'std', 'min', '25%', '50%', '75%', 'max', 'range']`.
- Every column is `float64`.
- The index holds the numeric column names, is named `'column'`, and is sorted ascending.
- `'range'` is `max - min` for each column.
Example:
```python
df = pd.DataFrame({
"b": [4, 1, 7],
"name": ["x", "y", "z"],
"a": [1.0, 2.0, 3.0],
"city": ["p", "q", "r"],
"c": [10, 10, 40],
})
report = numeric_describe_report(df)
report.columns.tolist()
# ['count', 'mean', 'std', 'min', '25%', '50%', '75%', 'max', 'range']
report.index.name # 'column'
report.index.tolist() # ['a', 'b', 'c'] (sorted ascending)
```
The values of `report` are:
| column | count | mean | std | min | 25% | 50% | 75% | max | range |
|---|---|---|---|---|---|---|---|---|---|
| a | 3.0 | 2.0 | 1.000000 | 1.0 | 1.5 | 2.0 | 2.5 | 3.0 | 2.0 |
| b | 3.0 | 4.0 | 3.000000 | 1.0 | 2.5 | 4.0 | 5.5 | 7.0 | 6.0 |
| c | 3.0 | 20.0 | 17.320508 | 10.0 | 10.0 | 10.0 | 25.0 | 40.0 | 30.0 |
```hint Check the defaults
Look up which columns `describe()` picks when you pass no arguments, both when the frame has datetime columns and when it has no numeric columns at all.
```
### Constraints & Assumptions
- `df` can mix integer, float, object, boolean and datetime columns. Only integer and float columns belong in the report.
- `df` may have no numeric columns, and numeric columns may contain NaN.
### What a Strong Answer Covers
- Selecting the numeric columns explicitly and leaving `df` unchanged.
- Transposing so each numeric column is a row, and deriving `range` from `max` and `min`.
- Enforcing the exact column order, `float64` dtypes, the index name and the ascending sort.
- Returning a report with the full schema when there are no numeric columns.
### Follow-up Questions
- How would you also report the interquartile range (IQR)?
- What should the function return if `df` has no numeric columns?
- How would you add the share of missing values per column to the report?
Overview: Write a pandas function that summarizes the numeric columns of a DataFrame with describe(), transposes the result into one row per column and adds a range column. It tests numeric column selection, reshaping, exact column order and dtypes, index naming and the case with no numeric columns.