np.where()详解||做量化知道这些就够了
发布日期:2021-05-07 14:28:36 浏览次数:16 分类:原创文章

本文共 226 字,大约阅读时间需要 1 分钟。


  • numpy.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写于上海

上一篇:prod()与cumprod()区别cumsum()
下一篇:pd.merge()详解||做量化知道这些就够了

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年04月07日 05时01分07秒