Outlier Detection in Python
Identify and handle outliers using IQR, z-score and visualisation methods
Outliers are data points that are significantly different from the rest — they can represent genuine extreme events (a record-breaking sale) or data quality issues (a data entry error). Detecting them before analysis prevents skewed averages and incorrect conclusions.
Two standard statistical methods: IQR (Interquartile Range) method and Z-score method. Both should be used alongside visualisation (boxplots, histograms) for context.
Example
Key Points
- ✓IQR method: outliers are below Q1 − 1.5×IQR or above Q3 + 1.5×IQR
- ✓Z-score > 3 (or < −3) usually indicates an outlier in normally distributed data
- ✓Investigate before removing — an outlier might be a legitimate high-value transaction
- ✓Capping (clip) is safer than dropping — you keep the row but limit the extreme value
- ✓Boxplot visualises the IQR: the box is Q1 to Q3, the whiskers extend to 1.5×IQR
Practice Question
In the IQR method for outlier detection, the upper fence is defined as:
Related Topics
Descriptive Statistics in PythonCalculate mean, median, mode, variance, standard deviation and percentilesSeaborn for Statistical ChartsCreate beautiful distribution, correlation and categorical charts with SeabornData Cleaning with PandasRename columns, fix data types, remove duplicates, and standardise messy real-world data