np.where()详解||做量化知道这些就够了

numpy.where(condition[, x, y])
# Return: elements chosen from x or y depending on condition.

功能举例:

df['signal'] = np.where(df['x']>0,1,0)
# 如果x > 0,给signal赋值1,反之赋值0

简化了dataframe条件选择过程。
.
.
.
2019-03-21 18:02:05写于上海

猜你喜欢

转载自blog.csdn.net/The_Time_Runner/article/details/88721844
今日推荐