0
0
Pandasdata~10 mins

Outlier detection with IQR in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the first quartile (Q1) of the 'data' column using pandas.

Pandas
Q1 = df['data'].quantile([1])
Drag options to blanks, or click blank then click option'
A0.25
B0.5
C0.75
D1.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0.5 which is the median instead of Q1.
Using 0.75 which is the third quartile.
2fill in blank
medium

Complete the code to calculate the interquartile range (IQR) from Q1 and Q3.

Pandas
IQR = Q3 [1] Q1
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Adding Q1 and Q3 instead of subtracting.
Multiplying or dividing Q3 and Q1.
3fill in blank
hard

Fix the error in the code to calculate the lower bound for outliers using IQR.

Pandas
lower_bound = Q1 [1] 1.5 * IQR
Drag options to blanks, or click blank then click option'
A-
B/
C+
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 1.5 * IQR instead of subtracting.
Using multiplication or division incorrectly.
4fill in blank
hard

Fill both blanks to create a dictionary of outliers below the lower bound and above the upper bound.

Pandas
outliers = {x: x for x in df['data'] if x [1] lower_bound or x [2] upper_bound}
Drag options to blanks, or click blank then click option'
A<
B>
C<=
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= or >= which includes boundary values.
Using wrong comparison operators that do not detect outliers.
5fill in blank
hard

Fill all three blanks to create a dictionary of non-outlier values within the IQR bounds.

Pandas
non_outliers = {x: x for x in df['data'] if x [1] lower_bound and x [2] upper_bound and x [3] None}
Drag options to blanks, or click blank then click option'
A>
B<
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators that include outliers.
Not checking for None values.