Problems / Remove Outliers / Editorial
Outlier removal using standard deviation is a common data cleaning technique.
Use scalar subqueries to compute the mean and standard deviation, then filter with BETWEEN:
BETWEEN
```sql
WHERE value BETWEEN
(SELECT AVG(value) - 2 * STDDEV(value) FROM measurements)
AND
(SELECT AVG(value) + 2 * STDDEV(value) FROM measurements)
```
Aggregate the statistics into a one-row DataFrame, then crossJoin it with the original data to make the thresholds available for filtering.
crossJoin
Note: STDDEV computes the sample standard deviation (divides by N-1), not the population standard deviation.
STDDEV
Solve Remove Outliers yourself →