IQR stands for Interquartile Range. It measures the middle 50% spread of the data between the 25th percentile (Q1) and the 75th percentile (Q3).
Click to reveal answer
beginner
How do you calculate the IQR from a dataset?
IQR = Q3 - Q1, where Q1 is the 25th percentile and Q3 is the 75th percentile of the data.
Click to reveal answer
intermediate
Why is IQR useful for detecting outliers?
IQR helps find outliers by identifying data points that fall below Q1 - 1.5*IQR or above Q3 + 1.5*IQR, which are unusually far from the middle 50% of data.
Click to reveal answer
beginner
Show the pandas code to calculate Q1, Q3, and IQR for a DataFrame column named 'data'.
D. The condition uses '&' instead of '|' to combine bounds
Solution
Step 1: Understand outlier condition
Outliers are values less than lower bound OR greater than upper bound, so conditions should be combined with OR (|).
Step 2: Check code condition
The code uses AND (&), which means no value can be both greater than upper bound and less than lower bound simultaneously.
Final Answer:
The condition uses '&' instead of '|' to combine bounds -> Option D
Quick Check:
Use '|' for outlier condition, not '&' [OK]
Hint: Use OR (|) to combine outlier conditions, not AND (&) [OK]
Common Mistakes:
Using AND instead of OR for outlier filtering
Swapping Q1 and Q3 values
Calculating IQR incorrectly
5. You have a DataFrame df with a column 'height'. You want to remove outliers using IQR but keep the original index. Which code correctly filters out outliers and keeps the index intact?