我想有一个更快的方法来做下面的一列数据帧。 现在我只能在for循环中这样做,而且速度很慢。但在使用lambda时,我不能依赖于last(x)
for i in range(len(Zscore_list)):
if len(Pos_list) != 0:
if Pos_list[i-1] == 1:
if Zscore_list[i] < -Thre2:
Pos_list.append(1)
else:
Pos_list.append(0)
elif Pos_list[i-1] == -1:
if Zscore_list[i] > Thre2:
Pos_list.append(-1)
else:
Pos_list.append(0)
elif Pos_list[i-1] == 0:
if Zscore_list[i] > Thre:
Pos_list.append(-1)
elif Zscore_list[i] < -Thre:
Pos_list.append(1)
else:
Pos_list.append(0)
else:
if Zscore_list[i] > Thre:
Pos_list.append(-1)
elif Zscore_list[i] < -Thre:
Pos_list.append(1)
else:
Pos_list.append(0)
可能有更多的方法可以做到这一点,但这里有一个可能的解决方案:
相关问题 更多 >
编程相关推荐