Vending machine sales outside the 1.5×IQR bounds

Write code · Medium · §8.4 Box plots and possible outliers

The list cans holds the number of drinks (cans) that each of ten campus vending machines sold in a day. Find Q1 and Q3 with pandas quantile(), and use the IQR (Q3 - Q1) to compute the lower bound Q1 - 1.5 * IQR and the upper bound Q3 + 1.5 * IQR.

Pick the values below the lower bound or above the upper bound as possible outliers, and print them once with print() as a Python list sorted from smallest to largest. If the same value is a possible outlier more than once, include it that many times. With the given values, the code prints [25], and if there are no possible outliers, it prints []. Print nothing else. Grading runs the code again with different values in cans.

Starter code

import pandas as pd

cans = [8, 9, 7, 10, 9, 8, 25, 9, 11, 8]

# Write your code here

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.