嵌套循环转为遍历多维数组:
for tp_ma in range(1, 10): for tp_before in range(1, 5): for tp_after in range(1, 6):
转后:
tp_ma, tp_before, tp_after = range(1, 10), range(1, 5), range(1, 6) tp_list = list(product(tp_ma, tp_before, tp_after)) temp_df = DataFrame(tp_list, columns=["ma", "before", "after"]) for index, row in temp_df.iterrows():
测试结果180次反而慢了50ms,奇怪。。。