Python
All Top Python Interview Questions#28
Winsorize and Cap Outliers with df.clip() in Pandas
MediumInterview Question #28
Given a `delivery_time_min` column with extreme outliers (e.g. 5,000 minutes due to sensor errors), winsorize the data by capping values at the 99th percentile upper bound and 1st percentile lower bound.
Input Table: df
11 rows preview| time_min |
|---|
| 12 |
| 15 |
| 18 |
| 20 |
| 22 |
| 25 |
| 28 |
| 30 |
| 35 |
| 40 |
| 5000 |
Expected Output Structure11 rows
| capped_time_min |
|---|
| 12.3 |
| 15 |
| 18 |
| 20 |
| 22 |
| 25 |
| 28 |
| 30 |
| 35 |
| 40 |
| 4504 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
Python 3.10 (Pandas)
Environment Ready
Starting the real Python + pandas runtime (one-time download)…