Draw the Box in Numbers

Data with PythonMedium+10 XP+10

Draw the Box in Numbers

A box plot is drawn from just a few numbers. Work them out yourself, the same way ax.boxplot does.

Task: write box_numbers(values) that returns a dictionary with these keys:

  • "q1", "median", "q3": the quartiles and median, worked out the way pandas quantile does
  • "low_whisker": the smallest value that is not below the low fence, Q1 − 1.5 × IQR
  • "high_whisker": the largest value that is not above the high fence, Q3 + 1.5 × IQR
  • "outliers": every value below the low fence or above the high fence, sorted from smallest to largest, repeats kept. Use [] if there are none.

The whiskers stop at real values from the list, not at the fences themselves. values has at least one number.

Examples

values = [12, 14, 15, 15, 16, 18, 19, 21, 95]
returns {'q1': 15.0, 'median': 16.0, 'q3': 19.0, 'low_whisker': 12.0, 'high_whisker': 21.0, 'outliers': [95.0]}
values = [1, 2, 3, 4, 5, 6, 7, 8]
returns {'q1': 2.75, 'median': 4.5, 'q3': 6.25, 'low_whisker': 1.0, 'high_whisker': 8.0, 'outliers': []}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run