I am trying to delete an item from a list if it is outside the interquartile range from the median.
Here is the list:
l = [69, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 87, 89]
The IQR, median and above and below the median are used with import numpy as np
iqr = np.subtract(*np.percentile(l, [75, 25]))
median = np.percentile(l, 50)
minus = median - iqr
plus = median + iqr
The minus number is 69 and the plus is 71 (using the IQR above and below the median)
However, when iterating through the list and trying to delete the items (87, 89) which is above/below the iqr. They are not get removed from the list.
for i in l:
if i < minus:
del i
if i > plus:
del i
When I print the list, it still shows 87, 89 in it.