此代码有效。但我不禁觉得这是一个 hack,尤其是“偏移”部分。我必须把它放在那里,否则每次我执行 del 操作时,删除中的所有索引值都会移动一个。
# remove outliers > devs # of std deviations
devs = 1
deletes = []
for num, duration in enumerate(durations):
if (duration > (mean_duration + (devs * std_dev_one_test))) or \
(duration < (mean_duration - (devs * std_dev_one_test))):
deletes.append(num)
offset = 0
for delete in deletes:
del durations[delete - offset]
del dates[delete - offset]
offset += 1
关于如何使它变得更好的想法?